0
votes

I could not figure why only hardcode filename work?

1) Without hardcoding filename . Problems:  Operation not permitted on IsolatedStorageFileStream 

2) But when I hardcode the filename, say, "Test.jpg"  in SaveImageFile()  and GetImageInISO(),
   I can view the image and there is no error message.


 1---------- save an Image from ImageControl :

Private void SaveImageFile()
{

  string strImgFile = strCountry + strCity + ".jpg";

  using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
   {

     using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(strImgFile, FileMode.Create, store))
       {                         
          WriteableBitmap wb = new WriteableBitmap(g_IntWidth, g_IntHeight);
          wb.Render(cn, new TranslateTransform());
          wb.Invalidate();

      System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, isfs, g_IntWidth, g_IntHeight, 0, 100);

      isfs.Close();                    

         }
    }

}


--2------------Read the image 

 private void GetImageInISO()
 {

     string strPassIn = strCountryName + strCityName + ".jpg";

     BitmapImage bmp = new BitmapImage();


  using (var store = IsolatedStorageFile.GetUserStoreForApplication())
   {

 using (IsolatedStorageFileStream isfs = store.OpenFile(strPassIn, System.IO.FileMode.Open,FileAccess.Read))

      {
           if (isfs.Length > 0)                           
             {                           
               bmp.SetSource(isfs);

                isfs.Close();
              }
             else
              {
                MessageBox.Show("Empty file");
               }                        
           }

       }
          image1.Width = bmp.PixelWidth;
           image1.Height = bmp.PixelHeight;
           image1.Source = bmp;
  }
}

1
Such error is usually caused by something else using the file that another piece of code is trying to retrieve. Also, your last 3 lines of code does not cover the case when bmp object is not being set, try wrapping those into if(bmp != null) { } clause.Eugene
I'm guessing this is b/c of threading, and you're running into this issue b/c your UI is something like a List of countries & cities, and they each have a different image which is retrived simultaneously via this method. Right? you should Lock around your using statementWilliam Melani
@Eugene: I tried all the possible ways. Result is the same. Work on hardcode filename and not the bmp issue.MilkBottle
It might help if you could post the code that shows how you save/retrieve data at the front end. Also, check to absolutely make sure that the file name that you are asking for really exists in the isolated storage.Eugene

1 Answers

0
votes

Thank all. Your advice help. the filename contain space characters in which it should not have. after remove the space, it works.