views:

90

answers:

2

Dumb question.. is this c# code intended to read local client files?

System.IO.FileStream content = System.IO.File.Open("c:\test.txt", System.IO.FileMode.Open);

It gives me error FILE NOT FOUND

I'm running Windows 7 and IE 8.

A: 

you forgot @ before "

System.IO.FileStream content = System.IO.File.Open(@"c:\test.txt", System.IO.FileMode.Open);

ofcourse you can do in this way:

System.IO.FileStream content = System.IO.File.Open("c:\\test.txt", System.IO.FileMode.Open);
Sebastian Brózda
+1  A: 

Having \ by itself means an escape character. You need to either use @ or double \

System.IO.FileStream content = System.IO.File.Open(@"c:\test.txt", System.IO.FileMode.Open);
or
System.IO.FileStream content = System.IO.File.Open("c:\\test.txt", System.IO.FileMode.Open);

If both fails..Check your NTFS permissions on the file.

Ash
Thanks. yes I need to escape the backslashes.. but still getting file not found. this file must be on the server right? not my client.
cyberpine
It's on whatever machine your code is running on!
Ash