Server.MapPath from a vb class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MattB

    Server.MapPath from a vb class

    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 HttpServerUtili ty
    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
  • snt

    #2
    Re: Server.MapPath from a vb class

    You have to use httpcontext to get the server object when you are on a
    class. Hope this helps

    snt


    Comment

    • Ibrahim ULUDAG

      #3
      Re: Server.MapPath from a vb class

      Don't write "dim Server As HttpServerUtili ty"
      just
      Dim path As String = Server.MapPath( "myfile.txt ")


      Ibrahim ULUDAG


      "MattB" <somedudeus@yah oo.com> wrote in message
      news:3gu0paFedc jhU1@individual .net...[color=blue]
      > 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 HttpServerUtili ty
      > 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[/color]


      Comment

      • MattB

        #4
        Re: Server.MapPath from a vb class

        tint wrote:[color=blue]
        > You have to use httpcontext to get the server object when you are on a
        > class. Hope this helps
        >
        > snt
        > http://www.flexoweb.com
        >[/color]

        Yep. HttpContext.Cur rent to be exact. Thanks!

        Matt

        Comment

        • kris kilowatt

          #5
          Re: Server.MapPath from a vb class


          Great, I had the same problem, HttpContext.Cur rent.Server.Map Path works
          perfect!



          --
          kris kilowatt
          ------------------------------------------------------------------------
          Posted via http://www.codecomments.com
          ------------------------------------------------------------------------



          Comment

          Working...