How to check if IsolStorageFile exists?

We have code like:

try  
{   
   streamOptions = new IsolatedStorageFileStream(  "FileName",  
                                                    FileMode.Open,  
                                                    FileAccess.Read);  
}  
catch ( FileNotFoundException )  
{  
   this.userSettings = new UserSettings();  
   load = false;  
}

This will cause Visual Studio to go into the debugger often when I am debugging, so I want to protect the above code with "if", so it only runs when the Inventor isolated file exists. However, it is unclear how to use IsolStorageFile.FileExists () to check the file that is going to open PropertyStorageFileStream , for example. what parameters do I need to give when I am a β€œnew” IsolatedStorageFile object.

+3
source share
3 answers
private bool IsolatedStorageFileExists(string name)
{
  using (var folder = IsolatedStorageFile.GetUserStoreForDomain())
  {
    return folder.FileExists(name);
  }
}
+2
source

You can use the FileExists method on the IsolStorageFile class.

+3
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (store.FileExists(your_file_name)) { do something if file exist }
                    else { do something if file not exist}
            }
+2

Source: https://habr.com/ru/post/1783397/


All Articles