How to read a text file in the website?

  • Thread starter Thread starter who be dat?
  • Start date Start date
W

who be dat?

I feel stupid for asking this but I can't figure this out. I've got some
text files I want my website to read. The text files are located in a
subdirectory of my application. Physically, the files are located on drive
C: in directory starting with InetPub/myapplication/directrory/files .
Thing is,when the website is running, the application path is
c:\windows\system32. I can manipulate the path to get this to work for now.
Thing is, once the application is done it may not be installed on Drive C:
much less under InetPub. What's the best way to get the path of the these
text files and access them? The files are stored in subdirectory of my
webprojoct called /emails. Thanks!

Chris Smith
 
You can use Server.MapPath method to get physical location of file
located in web applications directory.
Also you'll need to set rights to access this file for ASPNET user..

Tomas Petricek
Microsoft C# MVP

-----Original Message-----
From: who be dat? [mailto:[email protected]]
Posted At: Saturday, July 31, 2004 7:35 PM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: How to read a text file in the website?
Subject: How to read a text file in the website?

I feel stupid for asking this but I can't figure this out. I've got
some
text files I want my website to read. The text files are located in a
subdirectory of my application. Physically, the files are located on
drive
C: in directory starting with InetPub/myapplication/directrory/files .
Thing is,when the website is running, the application path is
c:\windows\system32. I can manipulate the path to get this to work for
now.
Thing is, once the application is done it may not be installed on Drive
C:
much less under InetPub. What's the best way to get the path of the
these
text files and access them? The files are stored in subdirectory of my
webprojoct called /emails. Thanks!

Chris Smith
 
Bah!! I forgot about MapPath. Grrr...

Now about this access for ASP.Net. As long as the directory is in the
project I created, all files in this directory should have such access,
right? I just tried this on my machine and it was able to retrieve and read
the text file from this directory just fine. I'm concerned when I release
this application and let others use it. Will they have to do something to
this directory.

Thanks for the help and the quick response.

Chris Smith
 
Read access should not be a problem, unless someone went and changed it
for the subdirectory. If you are planning to write to this file, then
you would have to grant Write access as this would be defaulted to
denied, but remember that if anyone requested for the Text file, it
will server to the client browser. So you should not place any sensitive
information in this file.

Regards,

Trevor Benedict R
 
Back
Top