default directory when reading a TXT file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all!

I've created an ASP.NET project using Visual Studio 2003 and C#. The project is quite basic in that it simply needs to read in the contents of a text file (.txt).

I have the StreamReader in place, but my problem arises when trying to local the file. I added my text file to my project in VS. I thought just putting the filename would locate the file thinking the default directory is the project directory: StreamReader("myFile.txt").

However, the program does not find the file. Instead, when I display the 'Path.GetFullPath(".")' I get: "C:\WINNT\system32".

I need the file to be read on my development machine (which is "localhost") and without program changes or hard-coding directory information, I also need it to read the file on my server when I copy the project out to the web.

Any suggestions would be greatly appreciated. I'm confident this issue is simple, but not from where I sit right now.

Thank you!

Mark
 
Look at using Server.MapPath( "/myFile.txt" );

and see what that returns.

bill

Mark said:
Hello all!

I've created an ASP.NET project using Visual Studio 2003 and C#. The
project is quite basic in that it simply needs to read in the contents of a
text file (.txt).
I have the StreamReader in place, but my problem arises when trying to
local the file. I added my text file to my project in VS. I thought just
putting the filename would locate the file thinking the default directory is
the project directory: StreamReader("myFile.txt").
However, the program does not find the file. Instead, when I display the
'Path.GetFullPath(".")' I get: "C:\WINNT\system32".
I need the file to be read on my development machine (which is
"localhost") and without program changes or hard-coding directory
information, I also need it to read the file on my server when I copy the
project out to the web.
Any suggestions would be greatly appreciated. I'm confident this issue is
simple, but not from where I sit right now.
 
Bill -- that did it! Thank you!

For some reason I keep getting an error message when I try to reply to the message you posted; hence I'm trying to reply to my original.

Thanks again,

Mark
 
Back
Top