Search code examples
f#access-deniedwriter

Access Denied when creating file in Visual F#


The following code runs without a hitch: enter image description here

On the other hand, I get an access-denied error with this:enter image description here

The destination is in my personal folder and I have full control. The directory is not read-only. Anyway, in either of those cases, the first code sample should not run either! I appreciate the help ...


Solution

  • In the second sample, you have two problems:

    1. There are back slashes instead of forward slashes, so some of them may get interpreted as escape sequences.
    2. You completely ignore the first parameter of write and specify what I assume is a folder as destination. You can't open a file stream on a folder, no wonder you get access denied.

    This should work:

    let write filename (ms:MemoryStream) =
      let path = System.IO.Path.Combine( "C:/Users/<whatever>/signal_processor", filename )
      use fs = new FileStream( path, FileMode.Create )
      ms.WriteTo(fs)