Search code examples
uwpdesktop-bridge

Win10S causes Certified W10 App to fail writing data to APPDATA


Our win10app was accepted earlier in Win10Store without problems, but now lately new Win10S requirements seem to cause certification/testing phase failure even while the appx package has not been changed for a year. App seem to fail certification because of app gives out a file write failure / access denied.

Our destop bridged app is simply storing data files to %appdata% folder, what would be the correct path to write user's own data files that works in both Win10S and Windows 10 Desktop?


Solution

  • UWP apps are supposed to write local data to the local app folder:

    %localappdata%\Packages\[app-package-name]\LocalState
    

    which is usually accessed through an StorageFolder object returned by the ApplicationData.LocalFolder property.

    using Windows.Storage;
    using System.Threading.Tasks;
    
    // Get the app's local folder.
    StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
    
    // Create a new file in the current folder.
    // Raise an exception if the file already exists.
    string desiredName = "test.txt";
    StorageFile newFile = await localFolder.CreateFileAsync(desiredName, CreationCollisionOption.FailIfExists);
    

    You can use the same code in your desktop bridge app to access the local folder of your app.