Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.IO.WriteAllBytes - Access to path denied error

Tags:

c#

winforms

Currently developing a C# WinForms application in Visual Studio 2010 .NET 4 on Windows 7.

Firstly I am reading a stream of bytes from a file using the File.ReadAllBytes() method. Then when attempting to write the file back, I am getting a access to path denied error when using the WriteAllBytes method.

I have tried passing in literal paths, Environment.SpecialFolder.ApplicationData, Path.GetTempPath(), but all are providing me with the same error.

I have checked permissions on these folders and also attempted to start the program in administrator mode with no luck.

like image 314
user1097734 Avatar asked Apr 27 '12 12:04

user1097734


People also ask

Why is access to the path denied?

You may see “Access to the path is denied” error if the application is not able access to a path that is trying to read or write. This will show up as 401 Unauthorized error in IIS logs.


1 Answers

Make sure that you specify the entire path when using File.WriteAllBytes() including file name.

File.WriteAllBytes() cannot write to a general directory, it has to write to a specific file.

Hope this helps.

like image 105
VentingOlive Avatar answered Nov 15 '22 20:11

VentingOlive