0
在我的应用程序中,我将位图转换为PNG并将其存储在文件夹内的文件中。当我试图再次打开文件写第二次时,我得到一个UnauthorisedAccessException
说"Access is denied"
。 单击保存按钮时,将调用以下函数。UnauthorizedAcessException尝试从WP8中的文件夹打开文件
private async void SaveClicked(object sender, RoutedEventArgs e)
{
WriteableBitmap wb = new WriteableBitmap(InkCanvas2, null);
Image image = new Image();
image.Height = 150;
image.Width = 450;
image.Source = wb;
await SaveToStorage(wb, image);
TransparentLayer.Visibility = System.Windows.Visibility.Collapsed;
}
的SaveToStorage具有下面的代码
private async Task SaveToStorage(WriteableBitmap i, Image im)
{
try
{
var dataFolder = await local.CreateFolderAsync("Page", CreationCollisionOption.OpenIfExists);
using (var testpng = await dataFolder.OpenStreamForWriteAsync("testpng.png", CreationCollisionOption.ReplaceExisting))
// HITS EXCEPTION AND GOES TO CATCH BLOCK
{
i.WritePNG(testpng);
testpng.Flush();
testpng.Close();
}
}
catch(Exception e)
{
string txt = e.Message;
}
}
它节省了第一次,没有错误,第二时间,则抛出异常。任何想法为什么发生这种情况