/// <summary>
/// Delete the indicated application file
/// </summary>
/// <param name="strFilePathName">The file path name to delete</param>
/// <returns>True, if successful; else false</returns>
public async static Task<bool> DeleteAppFile(string strFilePathName)
{
try
{
StorageFile fDelete = null;
if (!strFilePathName.Equals(""))
{
fDelete = await ApplicationData.Current.LocalFolder.GetFileAsync(strFilePathName);
if (fDelete != null)
{
try
{
await fDelete.DeleteAsync();
}
catch (Exception ex)
{
AFFECTS.App.ShowMessage(true, "Error", "DeleteAppFile {" + strFilePathName + "}", ex.Message);
return false;
}
return true;
}
}
else
AFFECTS.App.ShowMessage(true, "Error", "DeleteAppFile", "File path name is empty.");
}
catch (Exception ex)
{
AFFECTS.App.ShowMessage(true, "Error", "DeleteAppFile {" + strFilePathName + "}", ex.Message);
}
return false;
}
也許文件被打開了一些地方?如果你可以看到它在一個圖片控件或類似的刪除無法運行 – 2013-02-20 11:31:54
我會朝着那個方向 – Sw1a 2013-02-20 13:13:35
如果您將照片加載到BitmapDecoder或BitmapImage它將被鎖定,只要BitmapDecoder或BitmapImage是如果您未指定BitmapCacheOption.OnLoad,則使用該屬性。那麼你也會拒絕訪問。 – 2013-02-20 15:10:28