newbie: MapPath from non page class

  • Thread starter Thread starter KMA
  • Start date Start date
K

KMA

Ah yes. The MapPath function and the "~" . They're really taken out some of
the headaches for me. But alas (and alack) it's only available in the Page
class. What I wanted to do was write a separate class (code only, no GUI)
for handling data and be able to find the data files using MapPath from
within this class. Is there a way to use the MapPath functionality from non
page derivatives? Or can I use some kind of static function to return a ref
to Server object?

Or do I have to use the app start page to prime some global variable with
the datafile path?
 
I'm not sure if I know exactly what you want but here is a shot. You
want to use the mappath function in a class behind the scenes. The
easiest way to do this is
You will need to reference System.Web.
Then add the following code.
System.Web.HttpContext.Current.Server.MapPath(@"..\..\FolderName")
 
For a non-page class check out httpcontext.current, e.g.
httpcontext.current.server.mappath()

Bill
 
Yep. That's exactly what I wanted. Now that I've seen it I'm kicking myself
that I never saw it for myself. Still, I did mark the post "Newbie".

Cheers again.
 
Back
Top