2013-02-12 116 views
0

我正在一个名为“webapplication”的文件夹中创建一个带有静态html文件的windows phone项目。我想将“webapplication”文件夹的所有内容存储在独立存储中。有人可以帮助解决这个问题吗?在独立存储中存储项目文件夹

+0

本网站基于mu实际的尊重和反馈!我看到你是一个新用户,但如果解决方案有帮助,你应该回应并感谢那些懒得花时间回答问题的人。 – Saurabh 2013-02-13 13:35:47

回答

0

查看windows phone geek http://windowsphonegeek.com/tips/all-about-wp7-isolated-storage-files-and-folders了解隔离存储的信息。

要创建一个文件夹,请执行以下操作:

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); 
myIsolatedStorage.CreateDirectory("NewFolder"); 

如果你想创建该文件夹中的文件,然后:

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); 
StreamWriter writeFile = new StreamWriter(new IsolatedStorageFileStream("NewFolder\\SomeFile.txt", FileMode.CreateNew, myIsolatedStorage)); 

如果您正在寻找将文件复制到IsolatedStorage,然后您需要在第一次执行应用程序时运行以下代码:

using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) 
      { 
       string[] files = System.IO.Directory.GetFiles(folderPath); 
       foreach (var _fileName in files) 
       { 
        if (!storage.FileExists(_fileName)) 
        { 
         string _filePath = _fileName; 
         StreamResourceInfo resource = Application.GetResourceStream(new Uri(_filePath, UriKind.Relative)); 
         using (IsolatedStorageFileStream file = storage.CreateFile("NewFolder\\SomeFile.txt", FileMode.CreateNew, Storage)) 
         { 
          int chunkSize = 102400; 
          byte[] bytes = new byte[chunkSize]; 
          int byteCount; 

          while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0) 
          { 
           file.Write(bytes, 0, byteCount); 
          } 
         } 
        } 
       } 
      } 
+0

嗨对不起,迟到的回复,上述答案不服务我的需要。我想通过放置在windows phone – Manic 2013-03-05 12:56:49

+0

的visual studio项目目录中的文件进行循环如果你有文件夹路径(webapplication?),那么你可以使用System.IO.Directory.GetFiles(string path)来获取所有文件在该文件夹中。然后,您可以使用上述相同的方法复制每个文件。我修改了包含此建议的答案 – Saurabh 2013-03-05 20:28:06