Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

c# - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...