Developer
Developer

Reputation: 385

Save image in the windows phone

I am getting this error whenever i try to save my file-

   1. System.IO.IsolatedStorage.IsolatedStorageException was unhandled  
        Message=Operation not permitted on IsolatedStorageFileStream.  
        StackTrace:
               at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String
        path, FileMode mode, FileAccess access, FileShare share, Int32
        bufferSize, IsolatedStorageFile isf)
               at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String
        path, FileMode mode, FileAccess access, IsolatedStorageFile isf)
               at System.IO.IsolatedStorage.IsolatedStorageFile.OpenFile(String path,
        FileMode mode, FileAccess access)
               at PaintBrush.Save.savepic()
               at PaintBrush.Save..ctor()
               at PaintBrush.MainPage.click_btnSave(Object sender, RoutedEventArgs e)
               at System.Windows.Controls.Primitives.ButtonBase.OnClick()
               at System.Windows.Controls.Button.OnClick()
               at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs
        e)
               at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl,
        EventArgs e)
               at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32
        actualArgsTypeIndex, String eventName)

I am trying to save an image. I have gone through google and find that they are saying to close the filestream before writing but i can't get that.Because i have got the same error when i closed my filestream before writing. Here is my code--

public  void savepic()
        {
            string filename=DateTime.Today.ToString()+".jpg";

            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(filename, FileMode.Open, FileAccess.ReadWrite))
                {
                    MediaLibrary mediaLibrary = new MediaLibrary();
                    Picture pic = mediaLibrary.SavePicture(filename, fileStream);
                    fileStream.Close();
                }
            }

            PhotoChooserTask photoChooserTask = new PhotoChooserTask();
            photoChooserTask.Show();
        }

Upvotes: 1

Views: 2617

Answers (2)

gopinath
gopinath

Reputation: 1

MessageBar.Text = "Uploading to SkyDrive";
IsolatedStorageFileStream fileStream = null;
//string strSaveName = "images.jpg";               
try
{
   using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
   {
      fileStream = store.OpenFile("contact.txt", FileMode.Open, FileAccess.Read);
   }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
client.UploadAsync("me/SkyDrive", "contact.txt", fileStream, OverwriteOption.Overwrite);

Upvotes: 0

dumbfingers
dumbfingers

Reputation: 7089

Here's my snippet that might help you.

I think your problem lies on your OpenFile method.

 // Create a filename for JPEG file in isolated storage.
 String tempJPEG = "logo.jpg";
 // Create virtual store and file stream.
 using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
 {

     IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);

  // Encode WriteableBitmap object to a JPEG stream.
     Extensions.SaveJpeg(img, fileStream, img.PixelWidth, img.PixelHeight, 0, 85);
     fileStream.Close();
   }

Upvotes: 1

Related Questions