Server.MapPath

  • Thread starter Thread starter David C
  • Start date Start date
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! |
*******************************************
 
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! |
*******************************************
 
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
 
Back
Top