Monday, March 26, 2012

newbie: MapPath from non page class

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

"KMA" wrote:

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

"jmferguson" <jmferguson@.gmail.com> wrote in message
news:1108741296.751381.21490@.l41g2000cwc.googlegro ups.com...
> 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")

0 comments:

Post a Comment