using Server.MapPath in vb class

M

MattB

Server.MapPath works fine for me in a CodeBehind file, but when I try and
move that code to a vb class it doesn't. What do I need to change to make
Server.MapPath work from my vb class? Thanks!

Matt
 
K

Ken Cox [Microsoft MVP]

Since you are using Server, I suspect the class needs to be passed the
Httpcontext.

"The HttpContext.Server property provides programmatic access to the
properties and methods of the HttpServerUtility class. Because ASP.NET pages
contain a default reference to the System.Web namespace (which contains the
HttpContext class), you can reference the members of HttpContext on an .aspx
page without the fully qualified class reference to HttpContext. For
example, you can use just Server.CreateObject("MyCOMComponent") to create an
instance of a COM object on the server. If you want to use the members of
HttpServerUtility from an ASP.NET code-behind module, however, you must
include a reference to the System.Web namespace in the module and also fully
qualify the reference to the currently active request/response context and
the class in System.Web you want to use. For example, in a code-behind page
you must specify the full name
HttpContext.Current.Server.CreateObject("MyCOMComponent"). "

http://msdn.microsoft.com/library/d...frlrfsystemwebhttpcontextclassservertopic.asp
 
G

Guest

Make sure you are importing all the required Namespaces (System.Web)

If you have imported it and still having error, you will need to post error message to get any valuable commen

Kamran
 

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

Similar Threads


Top