代码之家  ›  专栏  ›  技术社区  ›  iLemming

如何获取文件并将其从隔离存储中移出?

  •  0
  • iLemming  · 技术社区  · 15 年前

     IsolatedStorageFile.CopyFile("storedFile.txt","c:\temp") 
    

    那不行。抛出IsolatedStorageException并说“不允许操作”

    1 回复  |  直到 14 年前
        1
  •  0
  •   Tim Coker    15 年前

    我在文件里什么都没看到除了 this

    作为一种解决方法,您可以打开该文件,读取其内容,然后像这样将它们写入另一个文件。

    using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
    {
        //write sample file
        using (Stream fs = new IsolatedStorageFileStream("test.txt", FileMode.Create, store))
        {
            StreamWriter w = new StreamWriter(fs);
            w.WriteLine("test");
            w.Flush();
        }
    
        //the following line will crash...
        //store.CopyFile("test.txt", @"c:\test2.txt");
    
        //open the file backup, read its contents, write them back out to 
        //your new file.
        using (IsolatedStorageFileStream ifs = store.OpenFile("test.txt", FileMode.Open))
        {
            StreamReader reader = new StreamReader(ifs);
            string contents = reader.ReadToEnd();
            using (StreamWriter sw = new StreamWriter("nonisostorage.txt"))
            {
                sw.Write(contents);
            }
        }
    }