this.Context.Server.MapPath

Discussion in 'ASP .Net Building Controls' started by crazyhorse, Jun 10, 2005.

  1. crazyhorse

    crazyhorse Guest

    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;
    }
    crazyhorse, Jun 10, 2005
    #1
    1. Advertising

  2. crazyhorse

    Teemu Keiski Guest

    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


    "crazyhorse" <> wrote in message
    news:...
    > 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;
    > }
    >
    Teemu Keiski, Jun 10, 2005
    #2
    1. Advertising

  3. crazyhorse

    crazyhorse Guest

    Context.Server.MapPath­("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.
    crazyhorse, Jun 10, 2005
    #3
  4. crazyhorse

    Teemu Keiski Guest

    Teemu Keiski, Jun 10, 2005
    #4
  5. crazyhorse

    Teemu Keiski Guest

    Teemu Keiski, Jun 10, 2005
    #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,112
    Scott M.
    Jan 17, 2010
  2. Peter Row
    Replies:
    0
    Views:
    453
    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,119
    Juan T. Llibre
    Mar 11, 2007
  4. Replies:
    4
    Views:
    944
    Juan T. Llibre
    Oct 7, 2007
  5. AAaron123
    Replies:
    11
    Views:
    1,185
    AAaron123
    Sep 9, 2009
Loading...

Share This Page