1

I am coding in C# for the first time and encountering this.

I use the function File.WriteAllBytes(OutputFileName, dest); which is creating a file on the disk and when my application tries to open the same file using file.Open giving me an exception Access to Path Denied. Please help me to get rid of this. I am on Windows 7, not running as administrator.

Thank you.

NeonGlow
  • 1,659
  • 4
  • 18
  • 36

3 Answers3

3

The file is closed. It is denied for other reasons. Check the path, or maybe you could open it with FileMode File.Open(path, FileMode.Open). Otherwise check your permissions.

Given a byte array and a file path, this method opens the specified file, writes the contents of the byte array to the file, and then closes the file.

Source

Robert Fricke
  • 3,637
  • 21
  • 34
1

The method WriteAllBytes closes the file after writing the byte array to the file so I guess your problem lies elsewhere.

Definition:

Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is overwritten.

More reading on the method: File.WriteAllBytes Method

Robert was ahead of me.. :)

Abbas
  • 14,186
  • 6
  • 41
  • 72
1

A couple of things spring to mind:

  1. Where are you saving the file to? Windows 7 seems to picky about saving to the root of C:\ these days.

  2. Permissions issue.

Woodz
  • 86
  • 3