namespace name 'Server' could not be found

  • Thread starter Thread starter Mortar
  • Start date Start date
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?
 
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)
 
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

Back
Top