469,963 Members | 2,022 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

what is SERVER a member of?

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
Nov 19 '05 #1
6 1419
From within a class, try using

System.Web.HttpServerUtility.MapPath

http://beta.asp.net/QUICKSTART/util/...pServerUtility


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"darrel" <no*****@hotmail.com> wrote in message
news:ev**************@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

Nov 19 '05 #2
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" <no***********@nowhere.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
From within a class, try using

System.Web.HttpServerUtility.MapPath

http://beta.asp.net/QUICKSTART/util/...pServerUtility


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"darrel" <no*****@hotmail.com> wrote in message
news:ev**************@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


Nov 19 '05 #3
> 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
Nov 19 '05 #4
> 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 Español
Ven, y hablemos de ASP.NET...
======================

"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:%2****************@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" <no***********@nowhere.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
From within a class, try using

System.Web.HttpServerUtility.MapPath

http://beta.asp.net/QUICKSTART/util/...pServerUtility


Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================

"darrel" <no*****@hotmail.com> wrote in message
news:ev**************@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



Nov 19 '05 #5

"darrel" <no*****@hotmail.com> wrote in message
news:Ow**************@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

Nov 19 '05 #6
> 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
Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Paul J. Landry | last post: by
12 posts views Thread by Steven T. Hatton | last post: by
3 posts views Thread by Steve Wark | last post: by
6 posts views Thread by SlashDrew | last post: by
1 post views Thread by =?Utf-8?B?am9uZWZlcg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.