Directory.Exists(imgFolder.Path);
win8.1商店应用中的替代方法, 即时尝试在线搜索,但我确实得到文件的结果只存在不检查文件夹存在
答案 0 :(得分:0)
在Windows 8.1中,您需要执行以下操作。
以下方法将检查文件是否存在:
public async Task<bool> isFilePresent(string fileName)
{
bool fileExists = true;
Stream fileStream = null;
StorageFile file = null;
try
{
file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
fileStream = await file.OpenStreamForReadAsync();
fileStream.Dispose();
}
catch (FileNotFoundException)
{
// If the file dosn't exits it throws an exception, make fileExists false in this case
fileExists = false;
}
finally
{
if (fileStream != null)
{
fileStream.Dispose();
}
}
return fileExists;
}
或:
public async Task<bool> isFilePresent(string fileName)
{
var item = await ApplicationData.Current.LocalFolder.TryGetItemAsync(fileName);
return item != null;
}