locked
Help with "file operation not permitted" RRS feed

  • Question

  • I have looked over the threads that has similar problems, and notice that they are all 1+ year old.

    I have also came upon this: Silverlight Open File

    So my first question is, is Lightswitch using silverlight 5? or 4?.

    Lastly my main question is, I have a custom silver light control that is basically an Openfile dialog. it has a browse, ok and cancel button. What I want to do is have the use select a ZIP file that contains a CSV file, and then populate my table with the data from the CSV. I am able to achieve this for a "Client" application, but when I switch to "Web" I get the file operation not permitted error.

    Can anyone give me some pointers.

    Some of the resources that I have already went over:


    • Edited by this.Y Tuesday, February 5, 2013 6:47 PM
    • Edited by Yann DuranModerator Wednesday, February 6, 2013 7:26 AM Fixed link text
    Tuesday, February 5, 2013 6:44 PM

Answers

  • Then the problem is probably somewhere in your SelectFileWindow class. Please debug your application in the manner as described by Simon Jones in this thread to figure out where the exception is coming from. He was looking for a NullReferenceException (actually, it was an ArgumentNullException) whereas you are looking for a SecurityException.

    Justin Anderson, LightSwitch Development Team

    • Marked as answer by this.Y Wednesday, February 13, 2013 1:34 PM
    Monday, February 11, 2013 10:19 PM
    Moderator

All replies

  • I would follow the advice on this thread. OpenFileDialog security exception

    You will also see that they link another one in the answer that should have the answer you are looking for.


    • Edited by Yann DuranModerator Wednesday, February 6, 2013 7:32 AM Fixed link text
    • Proposed as answer by Yann DuranModerator Wednesday, February 6, 2013 7:35 AM
    • Unproposed as answer by this.Y Friday, February 8, 2013 2:05 PM
    Tuesday, February 5, 2013 8:32 PM
  • It doesn't help me. Unless I am missing something, It doesn't have anything on how I can grab a file using the web client.
    Tuesday, February 5, 2013 9:17 PM
  • If you click on the link in the Glenn's reply, Error with OpenFileDialog, Justin's suggestion should be what you're looking for.

    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
     
    By doing this you'll help others to find answers faster.

    Wednesday, February 6, 2013 7:35 AM
    Moderator
  • @Yann,

    "I believe you will only see that the SecurityException is thrown when you try to chose a file that is not within the user's files and try to read its FullName property.  For example, if you choose a document found in the My Documents folder of the user, you'll be able to read the full path. "
    -Justin

    I get access path denied whether I choose a file from c:\temp or mydocument.

    Also a reminder, I was able to do what I wanted to do when the application is sete as "Local". I am only getting this error when its on the "web" setting.

    I am able to get the dialog box to show up, all the buttons on the dialog works. Its just that after I select files (using browse button) I get the "file operation not permitted" error.
    Wednesday, February 6, 2013 4:04 PM
  • Can you provide code so that we don't have to guess why you are getting the exception?

    Justin Anderson, LightSwitch Development Team

    Wednesday, February 6, 2013 11:14 PM
    Moderator
  • Okay here is the code. that deals with the selected file.

    Note that the error occur as soon as I double click on a file (while browsing).

    public partial class EditableGiftTablesGrid { Button btnImport = new Button(); partial void Import_Execute() { Dispatchers.Main.BeginInvoke(() => { SelectFileWindow selectFileWindow = new SelectFileWindow(); selectFileWindow.Closed += new EventHandler(SelectFileWindow_Closed); selectFileWindow.Show(); }); } void SelectFileWindow_Closed(object sender, EventArgs e) { SelectFileDialog selectFileDialog = (SelectFileDialog)sender; string selectFileStream = sender.ToString(); var parsedString = selectFileStream.Split(','); // Continue if they hit the OK button AND they selected a file if (selectFileDialog.DialogResult == true && (selectFileDialog.myStream != null)) { foreach (FileStream myZippedStream in selectFileDialog.myStream) { string zippedLocation = myZippedStream.Name; var parsedLocation = zippedLocation.Split('\\'); string fileName = parsedLocation[parsedLocation.Length - 1]; //filename is equal to something like "myfile.zip" // We want to turn that to "myfile.txt) fileName = (fileName.Substring(0, fileName.Length - 3)) + "txt"; string outputFile = ""; //We want to rebuild the path to the txt instead of zip foreach (string s in parsedLocation) { if (!s.Contains('.')) outputFile += (s + "\\"); else outputFile += fileName; } // This portion handles the zip file using (Zipfile myZip = new ZipFile(myZippedStream)); { try { ZipEntry myEntry = myZip.GetEntry(fileName); byte[] buffer = new byte[4096]; Stream zipStream = myZip.GetInputStream(myEntry); // Could the Error be here ??? using (FileStream streamWriter = File.Create(outputFile)) { StreamUtils.Copy(zipStream, streamWriter, buffer); } } catch { } finally { if (myZip != null) { myZip.IsStreamOwner = true; myZip.Close(); } } }

    //Could the error also be triggered here? using (FileStream fs = new FileStream(outputFile, FileMode.Open)) { ImportDataFile.importDataFile(fs, this.DataWorkspace); fs.Close(); fs.Dispose(); } } } } }







    • Edited by this.Y Friday, February 8, 2013 2:10 PM
    Friday, February 8, 2013 2:02 PM
  • Two Question for you?

    A. Is it nessisary to have the CSV in a zipped folder? That may cause some issues with a read/write path in certain cases.

    B. Which version of windows are you running that the path to Documents is C:/mydocuments. In all of my windows 7 instances it is in deeper path of say c:/windows/userprofiles/admin/documents/file.zip or am I missing somthing.

    Friday, February 8, 2013 8:18 PM
  • Two Question for you?

    A. Is it nessisary to have the CSV in a zipped folder? That may cause some issues with a read/write path in certain cases.

    B. Which version of windows are you running that the path to Documents is C:/mydocuments. In all of my windows 7 instances it is in deeper path of say c:/windows/userprofiles/admin/documents/file.zip or am I missing somthing.

    A: Yes it saves tons of spaces and each zip contains 2 files (one contains date time of creation of file and statistics of data. The other contains the data.).

    B: I don't think I hard coded any locations in my code, the location is gotten from the file that the user selects. And I tested selecting from: My document, temp folder, desktop, location on another server.

    Anymore questions?


    • Edited by this.Y Friday, February 8, 2013 8:29 PM
    Friday, February 8, 2013 8:27 PM
  • Your code is probably causing a SecurityException on this line:

    using (FileStream fs = new FileStream(outputFile, FileMode.Open))

    You are not allowed to open file streams to arbitrary locations on the file system. The only way you are allowed to interact with file streams is through some kind of user determined manner (e.g. OpenFileDialog and SaveFileDialog). This is a restriction for in-browser apps (enforced by Silverlight, not by LightSwitch).

    Out-of-browser applications can access arbitrary locations in the file system as long as the user has the correct permissions. Dynamic permission elevation is not considered.

    See the following MSDN documentation for more information about the capabilities of Trusted Applications. In-browser LightSwitch applications are not trusted whereas out-of-browser LightSwitch applications are trusted.


    Justin Anderson, LightSwitch Development Team

    • Proposed as answer by Dino HeModerator Monday, February 11, 2013 2:53 AM
    • Unproposed as answer by this.Y Monday, February 11, 2013 3:56 PM
    Saturday, February 9, 2013 12:14 PM
    Moderator
  • I just tested it today again and I took out my all the code of the "SelectFileWindow_closed" out and I still get the error. Maybe it is part of the silverlight limitation mentioned in the article you posted Justin.

    But I am kind of confused as to why if I follow Matt Sampson Article then it works. Maybe it has to do with the zip files.


    • Edited by this.Y Monday, February 11, 2013 3:56 PM
    Monday, February 11, 2013 2:52 PM
  • Then the problem is probably somewhere in your SelectFileWindow class. Please debug your application in the manner as described by Simon Jones in this thread to figure out where the exception is coming from. He was looking for a NullReferenceException (actually, it was an ArgumentNullException) whereas you are looking for a SecurityException.

    Justin Anderson, LightSwitch Development Team

    • Marked as answer by this.Y Wednesday, February 13, 2013 1:34 PM
    Monday, February 11, 2013 10:19 PM
    Moderator
  • Yes, I think you are right on this one, I looked in my code for the "Browse" button, and found a line that has:

    File.OpenRead, I think that is where the problem is. Anyway I decided going ASP is easier for this project so I am going that route.

    Thanks for pointers along the way guys. :)

    Wednesday, February 13, 2013 1:34 PM