Server.MapPath

Discussion in 'ASP .Net' started by David C, Dec 4, 2009.

  1. David C

    David C Guest

    What is syntax for Server.MapPath when I am in a class module? Thanks.

    David
    David C, Dec 4, 2009
    #1
    1. Advertising

  2. David C

    Leszek Guest

    Try:

    HttpContext.Current.Server.MapPath("path");



    Leszek

    "David C" <> wrote in message
    news:...
    > What is syntax for Server.MapPath when I am in a class module? Thanks.
    >
    > David
    >
    Leszek, Dec 4, 2009
    #2
    1. Advertising

  3. "David C" <> wrote in news:uEhqhLPdKHA.4112
    @TK2MSFTNGP06.phx.gbl:

    > What is syntax for Server.MapPath when I am in a class module? Thanks.


    Leszek has the answer. You also have to reference the web assembly to
    use it.

    NOTE: If this class library is not a UI library, I would not do it this
    way. You are tightly coupling the library to the an ASP.NET UI, which
    means you cannot easily refactor the application to any other type of
    UI. If this is a UI only library, then there is no issue, of course.

    Peace and Grace,

    --
    Gregory A. Beamer (MVP)

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
    Gregory A. Beamer, Dec 4, 2009
    #3
  4. "Leszek" <> wrote in news:uIWoUoPdKHA.4780
    @TK2MSFTNGP04.phx.gbl:

    > HttpContext.Current.Server.MapPath("path");


    The only potential issue I have with this is if the class library is a
    business layer (middle tier) assembly. This code will tightly couple the
    library to an ASP.NET UI.

    Peace and Grace,

    --
    Gregory A. Beamer (MVP)

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
    Gregory A. Beamer, Dec 4, 2009
    #4
  5. David C

    Leszek Guest

    You're sure right Gregory. Using HttpContext tights the code to the ASP.NET
    layer (we need to be in the HTTP Context in order to use the HttpContext :).
    I understand that David's question referred to a class within the App_Code
    folder (David said: "a class module") which is a part of the web
    application.

    If the "class module" means a class defined in an external assembly
    referenced by David's ASP.NET application it also would have access to the
    HttpContext. It is common to develop a set of WebControls as an additional
    assembly. These controls would have access to the application's HttpContext.

    The caveat of using HttpContext is pointed by Gregory:
    "you cannot easily refactor the application to any other type of UI"
    than ASP.NET

    Cheers,
    Leszek

    "Gregory A. Beamer" <> wrote in message
    news:Xns9CD786FAE7B67gbworld@207.46.248.16...
    > "David C" <> wrote in news:uEhqhLPdKHA.4112
    > @TK2MSFTNGP06.phx.gbl:
    >
    >> What is syntax for Server.MapPath when I am in a class module? Thanks.

    >
    > Leszek has the answer. You also have to reference the web assembly to
    > use it.
    >
    > NOTE: If this class library is not a UI library, I would not do it this
    > way. You are tightly coupling the library to the an ASP.NET UI, which
    > means you cannot easily refactor the application to any other type of
    > UI. If this is a UI only library, then there is no issue, of course.
    >
    > Peace and Grace,
    >
    > --
    > Gregory A. Beamer (MVP)
    >
    > Twitter: @gbworld
    > Blog: http://gregorybeamer.spaces.live.com
    >
    > *******************************************
    > | Think outside the box! |
    > *******************************************
    Leszek, Dec 4, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon
    Replies:
    5
    Views:
    11,124
    Scott M.
    Jan 17, 2010
  2. Peter Row
    Replies:
    0
    Views:
    457
    Peter Row
    Mar 1, 2004
  3. =?Utf-8?B?dHBhcmtzNjk=?=

    server.mappath vs. request.mappath

    =?Utf-8?B?dHBhcmtzNjk=?=, Mar 10, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,128
    Juan T. Llibre
    Mar 11, 2007
  4. Replies:
    4
    Views:
    951
    Juan T. Llibre
    Oct 7, 2007
  5. AAaron123
    Replies:
    11
    Views:
    1,188
    AAaron123
    Sep 9, 2009
Loading...

Share This Page