namespace name 'Server' could not be found

M

Mortar

in my class, i am trying to use Server.MapPath, but it says type or
namespace 'Server' can not be found.

i am using this in my webpages and it works fine. I thought maybe the
class was missing a using directive so i added all the same ones that
the webpages have but still no go.

anyone know what the problem is?
 
B

Bruce Barker

Server is property of the Page class that your page inherits from, it not a
global. if you are trying to access from a class, use
HttpContext.Current.Server

-- bruce (sqlwork.com)
 
K

Karl Seguin

Server is a property exposed by the Control class, unless your own class
also inherits from control (as do all pages, user controls and server
controls), it won't magically show up.

You can get a reference to the server class from your own class via:

HttpContext.Current.Server

note that if your class is consumed by a non-webclient, HttpContext.Current
will be null and thus you'll get a nullreference exception.

Karl
 

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

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top