Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP Check If File Exists

Tags:

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         {          } 

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".

Any help would be greatly appreciated.

like image 759
James Tordoff Avatar asked May 09 '16 15:05

James Tordoff


1 Answers

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

But not support 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/

like image 200
lindexi Avatar answered Oct 25 '22 02:10

lindexi