they use server.mapPath a lot to navigate it all.
Since I'm using these functions numerous times throughout my application, I
thought I'd move these into their own .vb class file and reference them that
way.
The catch is when moving these scripts over, 'Server.MapPath' turns into an
error "Name 'server' is not declared"
I'm assuming I need to expand Server.MapPath to show Server's parent class.
Alas, I have no idea what that is and google isn't helping much.
-DarrelFrom within a class, try using
System.Web.HttpServerUtility.MapPath
http://beta.asp.net/QUICKSTART/util...tpServerUtility
Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espaol
Ven, y hablemos de ASP.NET...
======================
"darrel" <notreal@.hotmail.com> wrote in message
news:evjWQaooFHA.3068@.TK2MSFTNGP15.phx.gbl...
>I have some functions that are reading/writing to the file system. As such,
> they use server.mapPath a lot to navigate it all.
> Since I'm using these functions numerous times throughout my application, I
> thought I'd move these into their own .vb class file and reference them that
> way.
> The catch is when moving these scripts over, 'Server.MapPath' turns into an
> error "Name 'server' is not declared"
> I'm assuming I need to expand Server.MapPath to show Server's parent class.
> Alas, I have no idea what that is and google isn't helping much.
> -Darrel
From what I can tell this will not help the OP as the MapPath method is not
static
To reply to the original question. Server is an instance member of the Page
class (well, it's in several places but I assume page is where you're
normally getting it from) and is, as Juan pointed out, of type
HttpServerUtility.
If you want to call Server.MapPath from a utility function, you have 2
choices:
1. pass in the Server object from the page to the utility function.
2. Use HttpContext.Current.Server.MapPath(). Through a bit of trickery
(well, thread local storage) this can dig out the server object associated
with the current request. N.B. If you call this function from a thread that
is not processing an HTTP request, it will barf at runtime.
HTH
Andy
"Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
news:%23pyDHiooFHA.904@.TK2MSFTNGP10.phx.gbl...
> From within a class, try using
> System.Web.HttpServerUtility.MapPath
> http://beta.asp.net/QUICKSTART/util...tpServerUtility
>
>
> Juan T. Llibre
> ASP.NET MVP
> http://asp.net.do/foros/
> Foros de ASP.NET en Espaol
> Ven, y hablemos de ASP.NET...
> ======================
> "darrel" <notreal@.hotmail.com> wrote in message
> news:evjWQaooFHA.3068@.TK2MSFTNGP15.phx.gbl...
>>I have some functions that are reading/writing to the file system. As
>>such,
>> they use server.mapPath a lot to navigate it all.
>>
>> Since I'm using these functions numerous times throughout my application,
>> I
>> thought I'd move these into their own .vb class file and reference them
>> that
>> way.
>>
>> The catch is when moving these scripts over, 'Server.MapPath' turns into
>> an
>> error "Name 'server' is not declared"
>>
>> I'm assuming I need to expand Server.MapPath to show Server's parent
>> class.
>> Alas, I have no idea what that is and google isn't helping much.
>>
>> -Darrel
>>
>>
> From what I can tell this will not help the OP as the MapPath method is
not
> static
I'm not quite sure what you mean by that.
Specifically, I'm taking a virtual path:
/documents/shared/ and mapping it to the actual server, be it my local one
when testing or the live server when deploying.
> To reply to the original question. Server is an instance member of the
Page
> class
Ah! Well, that explains it.
> 2. Use HttpContext.Current.Server.MapPath(). Through a bit of trickery
> (well, thread local storage) this can dig out the server object associated
> with the current request. N.B. If you call this function from a thread
that
> is not processing an HTTP request, it will barf at runtime.
This may be a naive question, but aren't all ASP.net threads part of a HTTP
request (ie, postbacks?)
-Darrel
> From what I can tell this will not help the OP as the MapPath method is not static
I wasn't looking too closely.
Thanks !
Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Espaol
Ven, y hablemos de ASP.NET...
======================
"Andy Fish" <ajfish@.blueyonder.co.uk> wrote in message
news:%23UEWcHpoFHA.2472@.tk2msftngp13.phx.gbl...
> From what I can tell this will not help the OP as the MapPath method is not static
> To reply to the original question. Server is an instance member of the Page class (well,
> it's in several places but I assume page is where you're normally getting it from) and
> is, as Juan pointed out, of type HttpServerUtility.
> If you want to call Server.MapPath from a utility function, you have 2 choices:
> 1. pass in the Server object from the page to the utility function.
> 2. Use HttpContext.Current.Server.MapPath(). Through a bit of trickery (well, thread
> local storage) this can dig out the server object associated with the current request.
> N.B. If you call this function from a thread that is not processing an HTTP request, it
> will barf at runtime.
> HTH
> Andy
>
>
> "Juan T. Llibre" <nomailreplies@.nowhere.com> wrote in message
> news:%23pyDHiooFHA.904@.TK2MSFTNGP10.phx.gbl...
>> From within a class, try using
>>
>> System.Web.HttpServerUtility.MapPath
>>
>> http://beta.asp.net/QUICKSTART/util...tpServerUtility
>>
>>
>>
>>
>> Juan T. Llibre
>> ASP.NET MVP
>> http://asp.net.do/foros/
>> Foros de ASP.NET en Espaol
>> Ven, y hablemos de ASP.NET...
>> ======================
>>
>> "darrel" <notreal@.hotmail.com> wrote in message
>> news:evjWQaooFHA.3068@.TK2MSFTNGP15.phx.gbl...
>>>I have some functions that are reading/writing to the file system. As such,
>>> they use server.mapPath a lot to navigate it all.
>>>
>>> Since I'm using these functions numerous times throughout my application, I
>>> thought I'd move these into their own .vb class file and reference them that
>>> way.
>>>
>>> The catch is when moving these scripts over, 'Server.MapPath' turns into an
>>> error "Name 'server' is not declared"
>>>
>>> I'm assuming I need to expand Server.MapPath to show Server's parent class.
>>> Alas, I have no idea what that is and google isn't helping much.
>>>
>>> -Darrel
>>>
>>>
>>
>>
"darrel" <notreal@.hotmail.com> wrote in message
news:Ow7NFRpoFHA.2156@.TK2MSFTNGP09.phx.gbl...
>> From what I can tell this will not help the OP as the MapPath method is
> not
>> static
> I'm not quite sure what you mean by that.
a static method of a class is one which you can invoke independently of
having an instance of that class - it's more like a global function. read up
on OO concepts if you're not clear on this.
> Specifically, I'm taking a virtual path:
> /documents/shared/ and mapping it to the actual server, be it my local one
> when testing or the live server when deploying.
so either of my proposed solutions should work for you
>> To reply to the original question. Server is an instance member of the
> Page
>> class
> Ah! Well, that explains it.
>> 2. Use HttpContext.Current.Server.MapPath(). Through a bit of trickery
>> (well, thread local storage) this can dig out the server object
>> associated
>> with the current request. N.B. If you call this function from a thread
> that
>> is not processing an HTTP request, it will barf at runtime.
> This may be a naive question, but aren't all ASP.net threads part of a
> HTTP
> request (ie, postbacks?)
yes (assuming the thread was created by asp.net to handle a request). I was
just making the point that if, for whatever reason, you call that function
from another thread (one you have started yourself or when including this
same utility function in a different application) it won't work
> -Darrel
> yes (assuming the thread was created by asp.net to handle a request). I
was
> just making the point that if, for whatever reason, you call that function
> from another thread (one you have started yourself or when including this
> same utility function in a different application) it won't work
Thanks, Andy. I appreciate the explanations!
-Darrel
0 comments:
Post a Comment