Reputation: 981
I want to create a folder named "TestFolder" on local folder of my uwp app. And need to upload files to it. It works fine on my system when I first manually create a folder((TestFolder) on local folder. but when I create app package for the project and tried to run it in another windows pc. It throws an error "System cant find the file specified". How can I resolve it?
StorageFolder appFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("TestFolder");
if (appFolder == null)
{
//Create folder
appFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("TestFolder");
}
Upvotes: 1
Views: 1591
Reputation: 374
You can modify your code this way to get your desired result,
StorageFolder appFolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("TestFolder");
if (appFolder == null)
{
//Create folder
appFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("TestFolder",CreationCollisionOption.OpenIfExists);
}
Upvotes: 1
Reputation: 1879
i would replace this few lines by this single line
var appFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("TestFolder", Windows.Storage.CreationCollisionOption.OpenIfExists);
Upvotes: 2