首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WP7:删除IsolatedStorageFile

WP7:删除IsolatedStorageFile
EN

Stack Overflow用户
提问于 2011-12-12 20:51:20
回答 1查看 494关注 0票数 0

如果你能帮我删除WP7上的IsolatedStorage文件,我会非常感激的。我基本上是从网上下载一个文件,将其存储在独立存储中,然后上传到我的Dropbox中的Downloads文件夹。上传文件后,我想从独立存储中删除该文件,但在尝试执行此操作时遇到异常错误。

下面是我的代码:

代码语言:javascript
复制
    public void readCompleteCallback(Object sender, OpenReadCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            try
            {
                //string fileName = txtUrl.Text.Substring(txtUrl.Text.LastIndexOf("/") + 1).Trim();
                string fileName = searchBox.Text + fileExt;
                //string fileName = "DownloadedNZB.nzb";
                bool isSpaceAvailable = IsSpaceIsAvailable(e.Result.Length);

                if (isSpaceAvailable)
                {
                    // Save mp3 to Isolated Storage
                    using (var isfs = new IsolatedStorageFileStream(fileName,
                                        FileMode.CreateNew,
                                        IsolatedStorageFile.GetUserStoreForApplication()))
                    {
                        long fileLen = e.Result.Length;
                        byte[] b = new byte[fileLen];
                        var numberOfBytesRead = e.Result.Read(b, 0, b.Length);
                        isfs.Write(b, 0, numberOfBytesRead);
                        isfs.Flush();
                        isfs.Close();

                        isf = IsolatedStorageFile.GetUserStoreForApplication();
                        stream = isf.OpenFile(fileName, FileMode.Open);

                        MessageBox.Show("File downloaded successfully");

                        App.GlobalClient.UploadFileAsync("/Public/", fileName, stream, (response) =>
                            {
                                MessageBox.Show("Uploaded file to Dropbox OK.");
                            },
                         (error) =>
                         {
                             MessageBox.Show(error + "Cannot upload file to dropbox.");
                         });
                    }
                    //stream.Close();
                    isf.DeleteFile(searchBox.Text + fileExt);
                }
                else
                {
                    MessageBox.Show("Not enough to space available to download the file");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        else
        {
            MessageBox.Show(e.Error.Message);
        }

    }

我不知道我错在哪里,但如果有人能给我指出正确的方向,我将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-12 21:10:05

您正在尝试删除using语句中的文件,其中的文件尚未关闭

UPD:您的上传是异步的,所以只有在上传完成后才能删除文件。将你的代码放在MessageBox.Show附近(“上传文件到Dropbox.”);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8474579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档