1

每当我尝试保存文件时,我都会收到此错误-

   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)

我正在尝试保存图像。我已经通过谷歌发现他们说在写入之前关闭文件流,但我无法理解。因为当我在写入之前关闭文件流时我遇到了同样的错误。这是我的代码-

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();
        }
4

2 回答 2

1

这是我的片段,可能会对您有所帮助。

我认为你的问题在于你的OpenFile方法。

 // 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();
   }
于 2012-10-29T16:23:58.720 回答
0
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);
于 2013-03-04T12:33:23.857 回答