Server.Mappath() method

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

    #1

    Server.Mappath() method

    Hello,

    I used Server.MapPath( mypath) method to find an absolute
    path of a file on a web server. But I got error message -
    Name 'Server' is not declared. I have imported System.IO.
    Does someone know any tricky here?

    Thanks in advance.

    Jane
  • Mattias Sjögren

    #2
    Re: Server.Mappath( ) method

    Jane,
    [color=blue]
    >I used Server.MapPath( mypath) method to find an absolute
    >path of a file on a web server. But I got error message -
    >Name 'Server' is not declared. I have imported System.IO.
    >Does someone know any tricky here?[/color]

    Where's your code located? Server is a property of the
    System.Web.UI.P age class so you have to put the code inside your page
    class, or pass a reference to the Page object to the method where you
    want to use Server.MapPath.

    System.IO has nothing to do with it.



    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • Jane

      #3
      Re: Server.Mappath( ) method

      Thanks so much, Mattias.

      I am developing a windows application that checks if a
      particular web page is on the web server. When I use
      system.IO.File. Exists(path) method to check it, path
      parameter has to be an absolute path. But I only know
      virtual path. Is there any other methods I can use to find
      an absolute path of a web page in a windows application?

      Jane

      [color=blue]
      >-----Original Message-----
      >Jane,
      >[color=green]
      >>I used Server.MapPath( mypath) method to find an absolute
      >>path of a file on a web server. But I got error message -[/color][/color]
      [color=blue][color=green]
      >>Name 'Server' is not declared. I have imported [/color][/color]
      System.IO. [color=blue][color=green]
      >>Does someone know any tricky here?[/color]
      >
      >Where's your code located? Server is a property of the
      >System.Web.UI. Page class so you have to put the code [/color]
      inside your page[color=blue]
      >class, or pass a reference to the Page object to the [/color]
      method where you[color=blue]
      >want to use Server.MapPath.
      >
      >System.IO has nothing to do with it.
      >
      >
      >
      >Mattias
      >
      >--
      >Mattias Sjögren [MVP] mattias @ mvps.org
      >http://www.msjogren.net/dotnet/ | [/color]
      http://www.dotnetinterop.com[color=blue]
      >Please reply only to the newsgroup.
      >.
      >[/color]

      Comment

      Working...