0

I am trying to create a text file in C: using code (shown in picture) It says access is denied. Please help.

enter image description here

Thanks

2
  • You don't have access to the root folder. Commented Jun 12, 2013 at 8:34
  • have you tried to investigate this issue yourself? there must be a lot of documentation regarding this kind of issue! Commented Jun 12, 2013 at 8:35

3 Answers 3

5

The root of the C: drive is protected (On Windows Vista, 7, etc), so users cannot write to it unless the process is elevated.

Try right clicking on your compiled exe and then Run As Admin to test this theory.

The solution is to save your file somewhere else. This may help- Lemme Tell Ya Where to Stick It and Where Should I Store my Data and Configuration Files

Or you may want to create a temp file: How can I create a temp file with a specific extension with .NET? - you should have the relevant permissions to save this file but it cannot be guaranteed.

Sign up to request clarification or add additional context in comments.

Comments

0

The user, who executes the program has no rights to create a file directly into the c:\ drive.

2 Comments

@FurqanSehgal: If you could do that, then there would be no point in having a security system at all.
You have to use another path or execute the program as Administrator. But you should handle the Exception for example with try catch ... msdn.microsoft.com/de-de/library/0yd65esw(v=vs.80).aspx
-1

vsFilePath should be something like c:\log.txt not c:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.