none
Isolated Storage user permissions. RRS feed

  • Question

  • I have a question regarding isolated storage access permissions. We use isolated storage in our application to store some files that need to be accessible for all users on the machine, thus we use machine-assembly level storage. But what we have found out is that if we want to delete one the files saved in the storage we get an exception because some of the user accounts have no right to delete these files (even though they can read and even modify them without any problems). Unfortunately we found no way to check in advance what rights the user has when it comes to isolated storage files since there is no way to find out the exact location of these files. This is a bit problematic since we would like to inform end user when he cannot proceed with the file deletion because he has no rights to do so. Perhaps there is some sort of way to find out what rights the user has without crashing on a failed attempt to delete these files?

    Thursday, September 1, 2011 12:02 PM

Answers

  • Hi Vadim,

    You can retrieve the path of an isolated storage file on disk by accessing a private field of the IsolatedStorageFileStream class, by using reflection. Here's an example:

    // Create a file in isolated storage.
    
    IsolatedStorageFile store = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
    
    IsolatedStorageFileStream stream = new IsolatedStorageFileStream("test.txt", FileMode.Create, store);
    
    StreamWriter writer = new StreamWriter(stream);
    
    writer.WriteLine("Hello");
    
    writer.Close();
    
    stream.Close();
    
    
    
    // Retrieve the actual path of the file using reflection.
    
    string path = stream.GetType().GetField("m_FullPath", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(stream).ToString();  
    
    

    I'm not sure that's a recommended practice though.

    Keep in mind that the location on disk depends on the version of the operation system and that you will need to make sure your other application has the permissions to access that location
     


    Regards, http://shwetamannjain.blogspot.com
    Friday, September 2, 2011 8:04 AM
  • I think you need to get the actual location of the files, then you can check whether the user has right to delete the files. About how to check user privilege , you can read this thread.
    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Tuesday, September 13, 2011 9:06 AM
    Tuesday, September 6, 2011 6:55 AM

All replies

  • Hi Vadim,

    Have you seen this link:

    http://www.codeproject.com/KB/files/UserFileAccessRights.aspx

     


    Regards, http://shwetamannjain.blogspot.com
    Friday, September 2, 2011 5:05 AM
  • I've checked your link, but unfortunately, like most other examples I have seen so far, this works only if you know exact path of the file you want to check. In my case were using isolated storage, which means there is no way to find out exact path of the file since it is generated randomly by the OS.
    Friday, September 2, 2011 6:38 AM
  • Hi Vadim,

    You can retrieve the path of an isolated storage file on disk by accessing a private field of the IsolatedStorageFileStream class, by using reflection. Here's an example:

    // Create a file in isolated storage.
    
    IsolatedStorageFile store = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
    
    IsolatedStorageFileStream stream = new IsolatedStorageFileStream("test.txt", FileMode.Create, store);
    
    StreamWriter writer = new StreamWriter(stream);
    
    writer.WriteLine("Hello");
    
    writer.Close();
    
    stream.Close();
    
    
    
    // Retrieve the actual path of the file using reflection.
    
    string path = stream.GetType().GetField("m_FullPath", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(stream).ToString();  
    
    

    I'm not sure that's a recommended practice though.

    Keep in mind that the location on disk depends on the version of the operation system and that you will need to make sure your other application has the permissions to access that location
     


    Regards, http://shwetamannjain.blogspot.com
    Friday, September 2, 2011 8:04 AM
  • Well, thats one way of doing it, but I'm somewhat reluctant to use private variables since you can never be sure when they might change.
    Friday, September 2, 2011 10:40 AM
  • I think you need to get the actual location of the files, then you can check whether the user has right to delete the files. About how to check user privilege , you can read this thread.
    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Paul Zhou Tuesday, September 13, 2011 9:06 AM
    Tuesday, September 6, 2011 6:55 AM