0
string[] targetFile = File.ReadAllLines(@"C:\d.txt");

I get "Could not find file".

I'm sure there is a d.txt at the root of C, any suggestions? i made a subdirectory called apples so c:\apples\d.txt i could still not read it.

this guy had the same exact problem http://www.pcreview.co.uk/forums/system-io-file-exists-windows-7-a-t3915728p2.html

I've tried running as administrator.

Suman Banerjee
  • 1,923
  • 4
  • 24
  • 40
  • Works for me. Do you have rights to read d.txt? Do you need to elevate? – Skrymsli Aug 30 '11 at 23:25
  • What are the results if you run your program with elevated permissions? It could (possibly) be a wonky ACL issue. – vcsjones Aug 30 '11 at 23:25
  • if you go to your project settings, are you compiling for x86, 64, or any CPU (il)? Does it make a different to switch to any from x86? – bryanmac Aug 30 '11 at 23:28
  • forgive a dumb question, but how do you elevate permissions when using debug mode in VS2010? –  Aug 30 '11 at 23:31
  • is it possible you don't have permissions to access the file. try run it as administrator. – The Mask Aug 30 '11 at 23:33
  • @Mike. You need to restart Visual Studio with permissions. From the Start menu - right-click Visual Studio and select Run As Administrator. – iandotkelly Aug 30 '11 at 23:34
  • I ran as admistrator and still no, i also copy and pasted that exact file name into run and it opens fine –  Aug 30 '11 at 23:37
  • i have UAC set to "never notify" –  Aug 30 '11 at 23:38
  • 7
    OK - One more (because I've done it - and no, I'm not proud of it) - In Explorer, are you hiding extensions? Could the file's full name (really) be `d.txt.txt`? Look at the properties of the file. – vcsjones Aug 30 '11 at 23:44
  • 2
    Oh my freaking....i'm going to go hide now –  Aug 30 '11 at 23:50

2 Answers2

2

It may be due to UAC and root access restriction for regular users. See this.

From UAC docs:

Non-administrator users cannot create files on the system root drive, for example, c:\

Community
  • 1
  • 1
Dmitry
  • 17,078
  • 2
  • 44
  • 70
0

Can you add it to subfolder.I suspect that C: drive has permission issue .

Or if you are running and EXE of that application run it with Admin privileges.

Pit Digger
  • 9,618
  • 23
  • 78
  • 122