- 1 year ago
How to save data under AppData\Roaming instead of AppData\Local\Packages
Comment
1 / 1
To save data under the AppData\Roaming
folder instead of AppData\Local\Packages
in a Windows Store app (UWP), you can use the ApplicationData.RoamingFolder
property. Here's how you can do it in C#:
csharpusing Windows.Storage;
// Get the RoamingFolder
StorageFolder roamingFolder = ApplicationData.Current.RoamingFolder;
// Create a file in the RoamingFolder
string fileName = "data.txt";
StorageFile file = await roamingFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
// Write data to the file
string dataToSave = "This is some sample data to save.";
await FileIO.WriteTextAsync(file, dataToSave);
With this code, the data will be saved under the AppData\Roaming
folder, and it will be synchronized across devices if the user is signed in with a Microsoft account.
Please note that in a UWP app, the access to certain folders like AppData\Local\Packages
is restricted, and you cannot directly save files there. Instead, use the appropriate StorageFolder
APIs provided by the Windows.Storage namespace to access the desired storage locations.