Tuesday, March 13, 2012

Server.MapPath in a class file

Hi All!

When I moved some code into a .cs file in the App_Code directory, it brokeServer.MapPath. I understand that this is becauseServer isn't directly available to the .cs file. What I'm wondering is if I can access theServer class that the code calling my .cs file so I can get an accurate physical path. Passing the physical path to the class in my .cs file isn't exactly practical. If I can't access the .aspx pageServer, how else can a .cs file retrieve the physical path of the application page that calls upon it?

Thanks for any help!

Brandon

You can access it from a class file as System.Web.HttpContext.Current.Server.
That's perfect, worked great! Thank you!

0 comments:

Post a Comment