嗨,我有一个简单的问题,我怎么能找到一个文件的路径,已经保存在隔离的存储
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()
(akak your local app storage box)
不需要反射,正如您在评论中所示。当你试图读取时,可以相对于文件夹,所以像/MyFolder/myFile.txt
这样的东西也可以工作,假设文件夹存在。
您的问题是这样的-将isostore中的相对路径推到Epub
类,这可能不会直接从isostore中读取,而是使用完整路径。Windows Phone操作系统的本质是,它不会让没有适当权限的第三方应用程序通过完整的路径引用直接访问内容。因此,您需要找到一种方法将二进制内容传递给类,而不是路径。