UWP检查文件是否存在 [英] UWP Check If File Exists
问题描述
我目前正在使用Windows 10 UWP App.该应用程序需要检查某个PDF文件是否存在,称为"01-introduction",如果打开,则将其打开.如果文件不存在,我已经有了代码.下面的代码是我目前拥有的:
I am currently working on a Windows 10 UWP App. The App needs to Check if a certain PDF File exists called "01-introduction", and if so open it. I already have the code for if the file does not exist. The Code Below is what i currently have:
try
{
var test = await DownloadsFolder.CreateFileAsync("01-Introduction.pdf", CreationCollisionOption.FailIfExists);
}
catch
{
}
此代码无法正常工作,因为要检查文件是否在此处,我尝试创建该文件.但是,如果该文件尚不存在,则会创建一个空文件.如果文件不存在,我不想创建任何内容,如果存在,则只需打开PDF.
This code Does not work correctly because to check if the file exists here, I attempt to create the file. However if the file does not already exist an empty file will be created. I do not want to create anything if the file does not exist, just open the PDF if it does.
如果可能的话,我想查看下载文件夹中名为我的手册"的文件夹.
If possible, i would like to look inside a folder which is in the downloads folder called "My Manuals".
任何帮助将不胜感激.
推荐答案
public async Task<bool> IsFilePresent(string fileName)
{
var item = await ApplicationData.Current.LocalFolder.TryGetItemAsync(fileName);
return item != null;
}
但不支持Win8/WP8.1
But not support Win8/WP8.1
这篇关于UWP检查文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!