我可以得到一个路径为IsolatedStorage文件,并从外部应用程序读取它?可以得到、并从、应用程序、路径

2023-09-02 21:44:44 作者:盛装出席只为错过你

我想写一个文件,其中外部应用程序可以读取它,但我想也有一些的IsolatedStorage优势,在发生意外的异常基本保险。我能有吗?

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?

推荐答案

您可以通过访问私有字段检索在磁盘上的独立存储文件的路径 IsolatedStorageFileStream 类,通过使用反射。这里有一个例子:

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.