【发布时间】:2013-07-13 00:10:51
【问题描述】:
我的程序想要从 Windows 文件系统中复制用户可能已经拥有其客户端的文件,并替换现有图像,该图像是应用程序中的缩略图/个人资料图像。
将新图像保存在旧图像之上:
async private void saveImage(string name, int clientId)
{
StorageFolder folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("ProfileImages", CreationCollisionOption.OpenIfExists);
try
{
StorageFile newFileImage = await StorageFile.GetFileFromPathAsync(photoImageStoragePath);
StorageFile originalFileImage = await StorageFile.GetFileFromPathAsync(originalPhotoImageStoragePath);
await newFileImage.CopyAndReplaceAsync(originalFileImage);
}
catch (Exception ex)
{
var name2 = string.Format("{0}_{1}{2}", name, GenerateId(), ".png");
copyImageAsync(folder, name2, clientId);
}
}
因此原始图像将被新图像替换。我正在根据那里的路径为每个文件创建新的存储文件,我确保我以前使用的所有文件流都是 .disposed() 所以我有点迷失为什么我一直被拒绝访问。如果我使用 copyandreplace 并且如果我使用 moveandreplace,我会得到它。
确切的错误代码是 System.UnauthorizedAccess - {"Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"}
【问题讨论】:
-
您如何获得
originalPhotoImageStoragePath?它的价值是什么?您的应用可能无权访问它。
标签: windows-runtime microsoft-metro