Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Server.MapPath

Reply
Thread Tools

Server.MapPath

 
 
David C
Guest
Posts: n/a
 
      12-04-2009
What is syntax for Server.MapPath when I am in a class module? Thanks.

David


 
Reply With Quote
 
 
 
 
Leszek
Guest
Posts: n/a
 
      12-04-2009
Try:

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



Leszek

"David C" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> What is syntax for Server.MapPath when I am in a class module? Thanks.
>
> David
>



 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      12-04-2009
"David C" <(E-Mail Removed)> 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! |
*******************************************
 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      12-04-2009
"Leszek" <(E-Mail Removed)> 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! |
*******************************************
 
Reply With Quote
 
Leszek
Guest
Posts: n/a
 
      12-04-2009
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" <(E-Mail Removed)> wrote in message
news:Xns9CD786FAE7B67gbworld@207.46.248.16...
> "David C" <(E-Mail Removed)> 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! |
> *******************************************



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments