Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get a path for a IsolatedStorage file and read it from external applications?

I want to write a file where an external application can read it, but I want also some of the IsolatedStorage advantages, basically insurance against unexpected exceptions. Can I have it?

like image 348
Jader Dias Avatar asked Jul 11 '09 01:07

Jader Dias


People also ask

Where is the isolated storage folder?

Isolated storage generally uses one of three locations to read and write data: %LOCALAPPDATA%\IsolatedStorage\ : For example, C:\Users\<username>\AppData\Local\IsolatedStorage\ , for User scope. %APPDATA%\IsolatedStorage\ : For example, C:\Users\<username>\AppData\Roaming\IsolatedStorage\ , for User|Roaming scope.

What is isolated storage file?

Isolated storage is designed to prevent data corruption and access to application-specific data, while providing a standard data storage and retrieval system that's inaccessible to users, folders or applications. Isolated storage serves as a virtual file system managed by the . NET Common Language Runtime (CLR).


1 Answers

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.

like image 122
mlessard Avatar answered Oct 23 '22 03:10

mlessard