How to check if file exists in a Windows Store App?

前端 未结 10 2044
小鲜肉
小鲜肉 2020-11-30 07:25

Is there any other way of checking whether a file exists in a Windows Store app?

try
{
    var file = await ApplicationData.Current.LocalFolder.GetFileAsync(         


        
10条回答
  •  眼角桃花
    2020-11-30 07:54

    I stumbled on to this blog post by Shashank Yerramilli which provides a much better answer.

    I have tested this for windows phone 8 and it works. Haven't tested it on windows store though

    I am copying the answer here

    For windows RT app:

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

    For Windows Phone 8

     public bool IsFilePresent(string fileName)
     {
         return System.IO.File.Exists(string.Format(@"{0}\{1}", ApplicationData.Current.LocalFolder.Path, fileName);
     }
    

    Check if a file exists in Windows Phone 8 and WinRT without exception

提交回复
热议问题