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

前端 未结 10 2032
小鲜肉
小鲜肉 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:56

    8.1 got something like this, I tried it worked.

    var folder = ApplicationData.Current.LocalFolder;
    var file = await folder.TryGetItemAsync("mytext.txt") as IStorageFile;
    
    if (file == null)
    {
       //do what you want
    }
    else
    {
       //do what you want
    }
    

    http://marcominerva.wordpress.com/2013/11/19/how-to-check-if-a-file-exists-in-a-windows-8-1-store-apps-no-more-exception-handling/

提交回复
热议问题