UWP检查文件是否存在 [英] UWP Check If File Exists

查看:54
本文介绍了UWP检查文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用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

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

这篇关于UWP检查文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆