UWP app does not copy file to AppData folder

泄露秘密 提交于 2019-12-06 14:48:44

Actually the app works as intended! Goal of UWP Desktop Bridge is to bring the main benefits of UWP to classic desktop apps. One of those benefits is safety and ability to uninstall easily.

Classic desktop apps have had the problem of being able to access files anywhere on the disk and especially being able to write anywhere without the user's knowledge. Uninstalling such apps then left behind many unnecessary traces on the hard drive and in registry and the PC then gradually became more and more cluttered.

Goal of UWP apps is that when they are uninstalled, they are gone completely, without a trace left on the disk.

To achieve this, UWP Desktop Bridge virtualizes some File System paths. See the File System section in documentation of Desktop Bridge where you can read the following:

In order to contain app state, the bridge attempts to capture changes the app makes to AppData. All write to the user's AppData folder (e.g., C:\Users\user_name\AppData), including create, delete, and update, are copied on write to a private per-user, per-app location. This creates the illusion that the packaged app is editing the real AppData when it is actually modifying a private copy.

The writes you performed in your code did actually work, but they did not write into the AppData\Roaming folder, but to a virtualized counterpart of this folder, which you can find in:

AppData\Local\Packages\{your app's ID}\LocalCache\Roaming\

Where your app's ID consists of the Package name and generated ID. You can usually find the folder faster by sorting folders by date of modification.

In the LocalCache\Roaming folder you will find the test\test.txt file you created. If you try to read from that file the read will again be virtualized from this location.

If you want to access the file using full path, you can retrieve it using the StorageFile APIs:

var filePath = Path.Combine( ApplicationDate.Current.LocalCacheFolder.Path, 
          "Roamingtest\test.exe" ));

The prerequisite for this is however that you add references to the UWP APIs. This is well described in this blogpost.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!