0
votes

I was trying to save multiple images into isolated storage by using creating a imageFolder in isolated storage and storing all my images inside.But it have an error so please anyone could help me solve the error or got other method way help me thanks.IF possible I would appreciate if you guys can show me your code that works. Actually my code would like to be under a button event handler.Thanks And the error is :Operation not permitted on IsolatedStorageFileStream.

My Code :

         private void SaveToLocalStorage(string imageFolder, string imageFileName)
    {
        imageFileName = name.Text;
        MessageBox.Show(imageFileName);

        var isf = IsolatedStorageFile.GetUserStoreForApplication();
        if (isf.DirectoryExists(imageFolder))
        {
            isf.CreateDirectory(imageFolder);
        }

        string filePath = Path.Combine(imageFolder, imageFileName);
        MessageBox.Show(filePath);
        using (var stream = isf.CreateFile(filePath))
        {
            var bmp= new WriteableBitmap(inkCanvas, inkCanvas.RenderTransform);
            bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
      }
}
1
What happens when you run your code? do you get any errors? If so, what and where? - Matt Lacey
ya there is an error.Error: Operation not permitted on IsolatedStorageFileStream. I could not solve . please help me - user801456
and at which line is this thrown? is the messagebox displayed? - Matt Lacey
the error was thrown at: using (var stream = isf.CreateFile(filePath) - user801456
and what is the value of filePath when it errors? - Matt Lacey

1 Answers

1
votes

First off, you probably want to be creating the directory if it DOESN'T exist, not if it does:

    if (!isf.DirectoryExists(imageFolder))
    {
        isf.CreateDirectory(imageFolder);
    }