what is SERVER a member of?

D

darrel

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
 
A

Andy Fish

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
 
D

darrel

From what I can tell this will not help the OP as the MapPath method is
not

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
 
J

Juan T. Llibre

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...
======================
 
A

Andy Fish

darrel said:
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
Ah! Well, that explains it.


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
 
D

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
 

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