0

如何解决异常,IsolatedFileStream 上不允许操作?

调试后发现某行没有读到,直接跳到catch部分。我正在从 windows phone 7 中的照片样本中读取图像,并将它们上传到 skydrive。有人可以指导我如何尽快解决这个问题吗?谢谢。

public BitmapImage fileName { get; set; }

private void GetImages()
{
    MediaLibrary mediaLibrary = new MediaLibrary();
    var pictures = mediaLibrary.Pictures;

    foreach (var picture in pictures)
    {
        BitmapImage image = new BitmapImage();
        image.SetSource(picture.GetImage());              

        MediaImage mediaImage = new MediaImage();
        mediaImage.fileName = image;
        UploadFile(mediaImage, picture.Name);                
    }
}

public void UploadFile(MediaImage image, string filepath)
{
   if (skyDriveFolderID != string.Empty) 
   {
     this.client.UploadCompleted += new EventHandler<LiveOperationCompletedEventArgs>(ISFile_UploadCompleted);
     infoTextBlock.Text = "Uploading backup...";
     dateTextBlock.Text = "";

     try
     {
        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
           // error occurs HERE
           IsolatedStorageFileStream readStream = myIsolatedStorage.OpenFile(filepath, FileMode.Open, FileAccess.Read);

           readStream.Close();
           this.client.UploadAsync(skyDriveFolderID, filepath, true, readStream, null)
        }
     }        
4

1 回答 1

0

你确定那里发生错误吗?我可以看到您在阅读之前关闭了流。所以可能是你弄错了错误行。

另外,您绝对确定,具有该确切名称的文件存在于独立存储中吗?

于 2012-05-02T15:41:54.490 回答