简体   繁体   中英

WP7 Exception error - Operation not permitted on IsolatedStorageFileStream

How do I solve the exception, Operation not permitted on IsolatedFileStream?

After debugging, I realised that a certain line wasn't read and it was skipped to the catch part. I am reading images from the photo samples in windows phone 7 as well as uploading them into skydrive. Can anybody guide me on how to solve this problem asap? Thanks.

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)
        }
     }        

Are you sure error occurs there? I can se you are closing the stream before reading it. So it may be that you got the line of error wrong.

Also, are you absolutely sure, that file with that exact name exists in Isolated Storage?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM