将项目文件夹存储在隔离存储中

时间:2013-02-12 04:35:47

标签: visual-studio-2010 windows-phone-7

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

1 个答案:

答案 0 :(得分:0)

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

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

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);
                            }
                        }
                    }
                }
            }