Windows Phone -保存多个文件IsolatedStorage
本文关键字:文件 IsolatedStorage 保存 Phone Windows | 更新日期: 2023-09-27 18:17:01
我的应用程序,文件是从web服务器下载并保存在IsolatedStorage(与web文件同名)。所以,我想保存多个文件IsolatedStorage,从多个url。还有更好的方法吗?
private void sinc(object sender, EventArgs e)
{
client = new WebClient();
url = "http://infassteste.url.ph/json.html";
Uri uri = new Uri(url);
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(uri);
}
private void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
string strFileName = url.Substring(url.LastIndexOf("/") + 1, (url.Length - url.LastIndexOf("/") - 1));
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
// Path Storage
// *** If File Exists
if (isoStore.FileExists(strFileName))
{
isoStore.DeleteFile(strFileName);
}
IsolatedStorageFileStream dataFile = new IsolatedStorageFileStream(strFileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, isoStore);
long fileLen = e.Result.Length;
byte[] b = new byte[fileLen];
e.Result.Read(b, 0, b.Length);
dataFile.Write(b, 0, b.Length);
dataFile.Flush();
object lenghtOfFile = dataFile.Length;
MessageBox.Show("Arquivo salvo!");
}
收集所有的uri到
List<URI> urls = new List<URI>();
然后使用foreach循环遍历它们并保存文件
foreach(Uri uri in urls)
{
// save files... perhaps client.OpenReadAsync(uri); ?
}