【发布时间】:2013-01-25 10:43:23
【问题描述】:
我有一个方法可以返回文件的正确路径
StorageFile newFile = null;
try
{
string pth = Path.Combine(ApplicationData.Current.LocalFolder.Path, dbPath);
newFile = StorageFile.GetFileFromPathAsync(pth).GetResults(); ;
}
catch (FileNotFoundException) { newFile = null; }
if (newFile == null)
{
string pth = Package.Current.InstalledLocation.Path + @"\Scriptures\" + dbPath;
StorageFile oldFile = StorageFile.GetFileFromPathAsync(pth).GetResults();
newFile = oldFile.CopyAsync(ApplicationData.Current.LocalFolder, dbPath, NameCollisionOption.FailIfExists).GetResults();
}
if (newFile == null) { throw new FileNotFoundException("Database File not Found"); }
return newFile.Path;
但有时我会遇到错误
StorageFile.GetFileFromPathAsync(pth).GetResults()
抛出的错误是:
StorageFile newFile = null;
try
{
string pth = Path.Combine(ApplicationData.Current.LocalFolder.Path, dbPath);
newFile = StorageFile.GetFileFromPathAsync(pth).GetResults(); ;
}
catch (FileNotFoundException) { newFile = null; }
if (newFile == null)
{
string pth = Package.Current.InstalledLocation.Path + @"\Scriptures\" + dbPath;
StorageFile oldFile = StorageFile.GetFileFromPathAsync(pth).GetResults();
newFile = oldFile.CopyAsync(ApplicationData.Current.LocalFolder, dbPath, NameCollisionOption.FailIfExists).GetResults();
}
if (newFile == null) { throw new FileNotFoundException("Database File not Found"); }
return newFile.Path;
我做错了什么?我是 c# 和线程的新手,这个错误让我很生气,因为有时它有效,有时它不。 请帮忙!
【问题讨论】:
-
尝试 newFile = await StorageFile.GetFileFromPathAsync(pth);
标签: c#-4.0 windows-8 windows-runtime storagefile