gpt4 book ai didi

c# - UWP 检查文件是否存在

转载 作者:可可西里 更新时间:2023-11-01 03:07:13 25 4
gpt4 key购买 nike

我目前正在开发 Windows 10 UWP 应用程序。该应用程序需要检查是否存在名为“01-introduction”的某个 PDF 文件,如果存在则打开它。如果文件不存在,我已经有了代码。下面的代码是我目前拥有的:

        try
{
var test = await DownloadsFolder.CreateFileAsync("01-Introduction.pdf", CreationCollisionOption.FailIfExists);
}
catch
{

}

此代码无法正常工作,因为要检查文件是否存在,我尝试创建文件。但是,如果文件不存在,将创建一个空文件。如果文件不存在,我不想创建任何内容,如果存在,只需打开 PDF。

如果可能的话,我想查看下载文件夹中名为“我的手册”的文件夹。

如有任何帮助,我们将不胜感激。

最佳答案

public async Task<bool> IsFilePresent(string fileName)
{
var item = await ApplicationData.Current.LocalFolder.TryGetItemAsync(fileName);
return item != null;
}

但不支持Win8/WP8.1

https://blogs.msdn.microsoft.com/shashankyerramilli/2014/02/17/check-if-a-file-exists-in-windows-phone-8-and-winrt-without-exception/

关于c# - UWP 检查文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37119464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com