Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MapPath inside c# class

Status
Not open for further replies.

fid

Programmer
May 10, 2001
20
US
Hi,

I have a class in which i'm trying to load a config text file that resides in the current directory. in the aspx file i can do a simple Server.MapPath("config.txt") to get the full path of the file (c:\inetpub\ etc..
inside the class however, i can't get Server.MapPath to work..
Diretory.GerCurrentDirectory() returns c:\WinNT\system32 so that try didn't work.

anyone know how i can grab a file in the current directory from a .cs class?

thanks
 
Where is your class/dll located? Is it in the same folder as your aspx file, or is it in c:\winnt\system32?

You're best bet for doing it within a class would probably be to hardcode it, if you knew that the config file would always be in the same place (and since its an aspx page, I wouldn't think the file would move around much on the web server)

Jack
 
Hi,
Thanks for responding.

the class is located in a .cs file MyClass.cs
namespace xyz {
public class a {
public void LoadConfig() {
FileStream _fs = new FileStream(@"c:\config.cfg", FileMode.Open, FileAccess.Read);
StreamReader _r = new StreamReader(_fs);
etc...

i call it from an aspx file
<%@ Page Language=&quot;C#&quot; src=&quot;lib/MyClass.cs&quot; %>
etc..

anyways, i want to load the config.cfg thats in the same lib folder as the MyClass.cs file.. so the application can be installed anywhere on a server, i was avoiding to hardcode the path so it would be portable.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top