all groups > asp.net building controls > june 2005 >
You're in the

asp.net building controls

group:

this.Context.Server.MapPath


this.Context.Server.MapPath crazyhorse
6/9/2005 8:40:13 PM
asp.net building controls: can get the Server.MapPath to work in run-mode, but not in the property
desinger window. It will throw an error. Try to read a xml file in
the Oninit. Works when you run a web page, but not while you open the
desinger properties window. What am i doing wrong, or is this is just
the way a control works. How can i initialize my property from a xml
file, without being in run mode.



protected override void OnInit(EventArgs e)
{
base.OnInit(e);
string ss="";
try
{
ss=this.Context.Server.MapPath("myxmlfile.xml");


}
catch
{

}
text2=ss;
}
Re: this.Context.Server.MapPath Teemu Keiski
6/10/2005 12:00:00 AM
MapPath cannot because it exists when there is a HttpContext alive (which
isn't the case in design mode) but you can use HttpUtility class during
design mode.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


[quoted text, click to view]

Re: this.Context.Server.MapPath Teemu Keiski
6/10/2005 12:00:00 AM
Sorry my bad, I meant HttpServerutility (missed the server word)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpServerUtilityClassTopic.asp

It has method MapPath

Teemu

Re: this.Context.Server.MapPath Teemu Keiski
6/10/2005 12:00:00 AM
Argh,

I'm tired and speaking holes to my head.

See this one, (free design-time xtension)
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1960&lngWId=10


--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Re: this.Context.Server.MapPath crazyhorse
6/10/2005 7:17:13 AM
Context.Server.MapPath=AD("myxmlfile.xml");

What is the HttpUtility to make the above code work in design-mode.
Looked up HttpUtility class. It is something like to convert a string
to HTML format and back again? Seems there is a bunch of methods like
HttpUtility.HtmlDecode and HtmlEncode and such.
AddThis Social Bookmark Button