locked
File operation not permitted RRS feed

  • Question

  • Hello:
    I have created a WCF service that will return a byte[] from a database field. I am able to successfully retrieve it from the:

    private void jt_ServiceCallCompleted(object sender, ServiceReference.ServiceCallCompletedEventArgs e)
    {
     if (e.Error == null)
     { 
      if (e.Result != null)
      {
       BArray = e.Result;  //a global variable
      }
     }
    }

    Then I click on a button to call the SaveFileDialog:
    private void SaveToFileBtn_Click(object sender, RoutedEventArgs e)
    {
     if (BArray == null) return;
     SaveFileDialog sfd = new SaveFileDialog();
     sfd.DefaultExt = ".doc";
     sfd.Filter = String.Format("Resume doc (*{0})|*{0}", ".doc");
     if (sfd.ShowDialog() == true)
     {
      using (FileStream fs = new FileStream(sfd.SafeFileName, FileMode.Create))
      {
       fs.Write(BArray, 0, BArray.Length);
      }
     }
    }

    What I am finding is that saveFileDialog.SafeFileName only returns the filename and not directory. I don't know if it is because the FileAccess permisson is denied for the directory or because SaveFileName only returns the filename. IN ANY CASE, I am getting the File operation not permitted. Access to path xxxx.doc denied error message.

    I have gone to the directory and set its permission to everyone, read/write, but that doesn't solve my problem.
    How can I save the file to a directory on my machine?

    Thanks

    Thursday, July 8, 2010 8:20 PM

Answers

  • Try this:

    using (Stream fs = sfd.OpenFile())
    {
                               
       fs.Write((BArray, 0, BArray.Length);
    }  

    Thursday, July 8, 2010 8:45 PM