Windows phone 7 Windows Phone 7:应用程序没有';t将从URL下载的PDF文件保存在独立存储中

Windows phone 7 Windows Phone 7:应用程序没有';t将从URL下载的PDF文件保存在独立存储中,windows-phone-7,c#-4.0,webclient,isolatedstorage,Windows Phone 7,C# 4.0,Webclient,Isolatedstorage,我正在开发一个应用程序来管理PDF文件(不是PDF查看器),我有一个专门的页面来下载带有特定URL的PDF文件 我的问题是应用程序不保存下载的文档 这是我的应用程序代码(在名为PDFurl.xaml.cs的页面类中): 我包括了一些messagebox来监视每个任务,但当它显示下载成功的消息时,它并没有保存任何东西 您如何知道PDF未保存?您是否用类似的方法检查了隔离存储。另外,您是否在写入后正确关闭流?事实上,我知道它是否使用VS 2010/12的独立存储资源管理器扩展名保存了文件。我只找到共

我正在开发一个应用程序来管理PDF文件(不是PDF查看器),我有一个专门的页面来下载带有特定URL的PDF文件

我的问题是应用程序不保存下载的文档

这是我的应用程序代码(在名为PDFurl.xaml.cs的页面类中):


我包括了一些messagebox来监视每个任务,但当它显示下载成功的消息时,它并没有保存任何东西

您如何知道PDF未保存?您是否用类似的方法检查了隔离存储。另外,您是否在写入后正确关闭
?事实上,我知道它是否使用VS 2010/12的独立存储资源管理器扩展名保存了文件。我只找到共享目录,但在该目录(以及包含的其他子目录)中也找不到它们。对于流问题,我相信这是正确的,我在其他实验的应用程序中使用了Save_Files()函数的同一部分代码来保存过程,效果很好……我不明白为什么在这个应用程序中不起作用,也许我不能用二进制数据方法保存PDF文件?
private void Start_Download(object sender, EventArgs e)
    {
        WebClient PDFdownloader = new WebClient();
        DownloadProgress.Visibility = Visibility.Visible;
        PDFdownloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(PDFdownloader_DownloadProgressChanged);
        PDFdownloader.OpenReadCompleted += new OpenReadCompletedEventHandler(PDFdownloader_OpenReadCompleted);
        PDFdownloader.OpenReadAsync(new Uri(UrlText.Text));
    }

    void PDFdownloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        try
        {
            DownloadProgress.Value = e.BytesReceived;
            DownloadProgress.Maximum = e.TotalBytesToReceive;
        }
        catch (Exception ex)
        {
            MessageBox.Show("Download failed!");
        }
    }

    void PDFdownloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        DownloadProgress.Visibility = Visibility.Collapsed;
        string[] fileNames = storage.GetFileNames();
        foreach (string fileName in fileNames)
        {
            if (fileName == (SavedFile.Text + ".pdf"))    //Save existing file
            {    
                MessageBoxResult rewrite = MessageBox.Show("Already exists a file with this name. Do you want to overwrite it?", "PDF name already used", MessageBoxButton.OKCancel);
                if (rewrite == MessageBoxResult.OK)
                {
                    storage.DeleteFile(SavedFile.Text + "pdf");
                    Save_File(e);
                }
                else
                {
                    MessageBox.Show("Document not saved!");
                    e.Result.Close();
                    DownloadProgress.Value = 0;
                    DownloadProgress.Visibility = Visibility.Collapsed;
                    return;
                }
            }
            else       //Save new file
            {
                Save_File(e);
            }
        }
    }

    private void Save_File(OpenReadCompletedEventArgs e)
    {
        using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(SavedFile.Text + ".pdf", FileMode.Create, storage))
        {
            byte[] buffer = new byte[1024];
            while (e.Result.Read(buffer, 0, buffer.Length) > 0)
            {
                stream.Write(buffer, 0, buffer.Length);
            }
            MessageBox.Show("File downloaded and saved successfully!");
            foreach (string file in storage.GetFileNames())
            {
                MessageBox.Show("Found " + file);
            }
        }   
    }