Access to the path 'C:\Users\xxx\Desktop' is denied

Probably you don't realize that you are trying to open the Desktop folder and then trying to use it as a file.

If your intent is to write the bytes of the image to your database then your code should be

  fsrw = new FileStream(fname , FileMode.Open, FileAccess.ReadWrite);

You may have to run your program/IDE as Administrator to access that folder, due to how Windows default permissions work.

For more context:

The path leads to a folder - not a file. I believe FileStreams in C-based languages must actually point to a file, rather than a directory: ie. C:\Users\Username\Desktop\file.extension


  1. Make sure to use a fully qualified name, including the file name for both the destination and the source. (e.g. C:\Source\file.ext, C:\Destination\file.ext)

  2. Visual Studio should run with the same access rights as the folders you are trying to access. Trying to access something like "My documents" and other locations that you don't need elevated rights to access shouldn't require you to elevate Visual Studio.

  3. You should not have to "acquire" or change the permissions on files and folders that you can normally access from the same user that you are running VS in.

LINK TO SOURCE: enter link description here


"C:\\Users\\username\\Desktop" is a directory for me; not a file.

Since you're attempting to open the file, this:

fsrw = new FileStream("C:\\Users\\Sainath\\Desktop", FileMode.Open, FileAccess.ReadWrite);

... should be

var fullpath = Path.Combine("C:\\Users\\Sainath\\Desktop", fname);
fsrw = new FileStream(fullpath, FileMode.Open, FileAccess.ReadWrite);