以下のコードを使用して、アプリがインストールされたフォルダーにフォルダーを作成しますが、常にアクセス拒否の例外を受け取ります。
StorageFolder appFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
if (!await CheckIfFolderExist(appDataFolderName))
{
StorageFolder appDataFolder = await appFolder.CreateFolderAsync(appDataFolderName);
StorageFolder userFolder = await appDataFolder.CreateFolderAsync(userFolderName);
StorageFolder contactFolder = await appDataFolder.CreateFolderAsync(contactFolderName);
}
else
{
StorageFolder appDataFolder = await appFolder.GetFolderAsync(appDataFolderName);
if (!await CheckIfSubFolderExis(appDataFolderName, userFolderName))
{
await appDataFolder.CreateFolderAsync(userFolderName);
}
if (!await CheckIfSubFolderExis(appDataFolderName, contactFolderName))
{
await appDataFolder.CreateFolderAsync(contactFolderName);
}
}
// Check if the app folder exists
private async Task<bool> CheckIfFolderExist(string folderName )
{
bool folderExist = false;
try
{
StorageFolder appFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder appDataFolder = await appFolder.GetFolderAsync(folderName);
folderExist = true;
return folderExist;
}
catch (FileNotFoundException ex)
{
return folderExist;
}
}
// Check if the app subfolder exists
private async Task<bool> CheckIfSubFolderExis(string folderName,string subFolderName)
{
bool subFolderExist = false;
try
{
StorageFolder appFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder subFolder = await appFolder.GetFolderAsync(subFolderName);
subFolderExist = true;
return subFolderExist;
}
catch (FileNotFoundException ex)
{
return subFolderExist;
}
}
誰にもアイデアがありますか?