Home All Groups Group Topic Archive Search About

Server.MapPath from a vb class

Author
10 Jun 2005 5:25 PM
MattB
I've used this a bit from codebehind with no problems, but now I'm
having some issues when I try to use it from a vb class in my application.
Looking in help, it looks like I need to do something like this:

dim Server As HttpServerUtility
Dim path As String = Server.MapPath("myfile.txt")

----

But any time I use that Server variable I get a null refrence exception.
What am I doing wrong? Thanks!

Matt

Author
10 Jun 2005 6:11 PM
snt
You have to use httpcontext to get the server object when you are on a
class.  Hope this helps

snt
http://www.flexoweb.com
Are all your drivers up to date? click for free checkup

Author
10 Jun 2005 8:10 PM
MattB
tint wrote:
> You have to use httpcontext to get the server object when you are on a
> class.  Hope this helps
>
> snt
> http://www.flexoweb.com
>

Yep. HttpContext.Current to be exact. Thanks!

Matt
Author
11 Dec 2005 3:45 PM
kris kilowatt
Great, I had the same problem, HttpContext.Current.Server.MapPath works perfect! -- kris kilowatt ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------
Author
10 Jun 2005 7:12 PM
Ibrahim ULUDAG
Don't write  "dim Server As HttpServerUtility"
just
  Dim path As String = Server.MapPath("myfile.txt")


Ibrahim ULUDAG
www.ibrahimuludag.com

Show quoteHide quote
"MattB" <somedud***@yahoo.com> wrote in message
news:3gu0paFedcjhU1@individual.net...
> I've used this a bit from codebehind with no problems, but now I'm having
> some issues when I try to use it from a vb class in my application.
> Looking in help, it looks like I need to do something like this:
>
> dim Server As HttpServerUtility
> Dim path As String = Server.MapPath("myfile.txt")
>
> ----
>
> But any time I use that Server variable I get a null refrence exception.
> What am I doing wrong? Thanks!
>
> Matt

Bookmark and Share