Windows phone 7 来自独立存储windows phone的路径
您好,我有一个简单的问题,我如何才能找到已保存在独立存储中的文件的路径Windows phone 7 来自独立存储windows phone的路径,windows-phone-7,isolatedstorage,Windows Phone 7,Isolatedstorage,您好,我有一个简单的问题,我如何才能找到已保存在独立存储中的文件的路径 using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(App.filePath, FileMode.Create, store)) { byte[] buffer = new byte[1024]; while (e.Result.Read(buf
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(App.filePath, FileMode.Create, store))
{
byte[] buffer = new byte[1024];
while (e.Result.Read(buffer, 0, buffer.Length) > 0)
{
stream.Write(buffer, 0, buffer.Length);
}
stream.Close();
}
现在我要读这个文件
我需要此路径将其用作方法的参数
Epub epub =new Epub([file path])
如果文件位于IsolatedStorage中,您可以自己放在那里,也可以是系统创建的用于存储设置的文件,我们将非常感谢您的帮助 如果你把它放在那里,你一定在之前的某个点有路径。您只需要跟踪正在使用的文件名(和路径) 您不应该尝试直接访问设置文件。试试这个
using (var AppStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
string[] filenames=AppStorage.getFileNames();
//choose the filename you want or
//enumerate directories and read file names in each directory
string[] directories=AppStorage.getDirectories();
}
对于每个目录,您必须将文件路径添加到该目录,就像在任何windows文件浏览中一样
希望有帮助。发布您的进一步查询。如果您是将文件放入隔离存储的人,则无需获取文件路径。关于如何正确地将文件读写到应用程序isostore的完整指南可用,这应该是您的出发点 整个读取程序仅限于此:
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("myFile.txt", FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(fileStream))
{
Console.WriteLine("Reading contents:");
Console.WriteLine(reader.ReadToEnd());
}
}
其中,myIsolatedStorage
等于IsolatedStorageFile.GetUserStoreForApplication()
(单击本地应用程序存储框)
正如您在评论中所显示的,无需反思。当您尝试读取时,可以相对于文件夹,因此,如果文件夹存在,则类似于/MyFolder/myFile.txt
的内容也可以工作
您的问题是,将isostore中的相对路径推送到
Epub
类,该类可能不会直接从isostore读取,而是使用完整路径。Windows Phone操作系统的本质是不允许没有适当权限的第三方应用程序通过完整路径引用直接访问内容。因此,您需要找到一种将二进制内容传递给类而不是路径的方法。如何获取我将文件放入隔离目录中的路径storage@hamza437我不明白你怎么会不知道你保存文件时使用的文件名,或者我怎么知道…@hamza437你能告诉我你尝试了什么吗我试图通过以下var path=stream.GetType().GetField(“m_RootDir”,BindingFlags.NonPublic | BindingFlags.Instance).GetValue(stream.ToString())获取文件:;但是我总是有一个例外“System.NullReferenceException”我需要这个路径来阅读epub书籍,因为我使用的是一个库,它需要的是文件路径而不是名称谢谢你的帮助