【问题标题】:Windows Phone - Save multiples files IsolatedStorageWindows Phone - 保存多个文件 IsolatedStorage
【发布时间】:2014-08-08 11:32:04
【问题描述】:

我的应用程序,该文件是从网络服务器下载的,并保存在独立存储中(与网络文件同名)。 所以,我想从多个 URL 将多个文件保存在 IsolatedStorage 上。有什么更好的方法?

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!");

    }

【问题讨论】:

    标签: c# visual-studio windows-phone-8 isolatedstorage


    【解决方案1】:

    收集所有 URI 到

    List<URI> urls = new List<URI>();
    

    然后使用 foreach 循环遍历它们并保存文件

    foreach(Uri uri in urls)
    { 
    // save files... perhaps client.OpenReadAsync(uri); ?
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多