newbie: MapPath from non page class

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?
 
J

jmferguson

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")
 
G

Guest

For a non-page class check out httpcontext.current, e.g.
httpcontext.current.server.mappath()

Bill
 
K

KMA

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.
 

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

Top