Click here to Skip to main content
14,389,999 members
Rate this:
Please Sign up or sign in to vote.
See more:

I am trying to create folder in C:\\Program Files\\ using code like this:
Directory.CreateDirectory("C:\\Program Files\\folderName").

But showing exception as : Access to the path 'C:\Program Files\folderName' is denied.

Please help me out.

Updated 25-Apr-13 4:10am
[no name] 25-Apr-13 8:45am
You need to run your application as an admin.
CHill60 25-Apr-13 8:46am
Do you have permissions on that PC to create folders?
Member 7686563 25-Apr-13 8:51am
Ya, if run exe as Administrator it is running if not its showing exception.
But I don't want to select everytime manually.
Is any possiblities to set permission for creating folder/files by c# code?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Two solutions to the permissions problem:

You need to set the appropriate permissions to Read from the source and Write to the target location for the user(s) of the exe.


You can impersonate a user with such permissions (in the code, use the credentials of another user to perform the action).
** See A complete Impersonation Demo in C#.NET[^]

Member 7686563 25-Apr-13 9:20am
Hi Edo,
unable to download source code.please check out.
Joezer BH 25-Apr-13 9:45am
The source code of the referenced article?

* If so, try this other article:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100