我正在一个名为“webapplication”的文件夹中创建一个带有静态 html 文件的 windows phone 项目。我想将“webapplication”文件夹的所有内容存储在隔离存储中。有人可以帮助解决这个问题吗?
问问题
107 次
1 回答
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);
}
}
}
}
}
于 2013-02-12T09:00:59.390 回答