default directory when reading a TXT file

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
 
W

William F. Robertson, Jr.

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top