TreeView Control - Basic Question with TreeNodeSrc

Discussion in 'ASP .Net Web Controls' started by Dennis Redfield, Feb 17, 2005.

  1. Ok. I have the TreeView Control working correctly as long as I do not use
    TreeNodeSrc. It seems that however I format the XML file used for
    TreeNodeSrc I get back the same error message:
    System.Xml.XmlException: The data at the root level is invalid. Line 1,
    position 1.\

    So what am I doing wrong? Details:


    The xml is well formed - copied from MSDN samples and looks like:

    <?xml version="1.0" encoding="utf-8"?>
    <TREENODES>
    <TreeNode Text="Contracts" Type="Folder"/>
    </TREENODES>

    the HTML fragment for the treeview looks like:

    <iewc:treeview id="TreeView1" runat="server"
    SelectExpands="True" AutoSelect="True"
    SystemImagesPath="images/treeimages/"
    TreeNodeSrc="xmlmadness.xml">
    <iewc:TreeNodeType ImageUrl="images/folder.gif" Type="Folder"
    ExpandedImageUrl="images/folderopen.gif"></iewc:TreeNodeType>
    </iewc:treeview>
    </iewc:treeview>

    thanks.
     
    Dennis Redfield, Feb 17, 2005
    #1
    1. Advertising

  2. Hi Dennis,

    Welcome to ASPNET newsgroup.
    From your description, it seems that you've encoutered an existing problem
    of the IE webcontrol. When we use the TreeNodeSrc to specify a xml data
    source, we need to configure the xml file (or the entire Virutal DIR) as
    allow Anonymous.

    In addition, we can also resolve the problem by specifying the
    "TreeNodeSrc" via physical file path , for example:

    private void Page_Load(object sender, System.EventArgs e)
    {
    this.TreeView1.TreeNodeSrc = Server.MapPath("./treebooks.xml");
    this.TreeView1.DataBind();
    }

    set the treenodesrc at runtime via code. Hope helps.

    Thanks & Regards,


    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Feb 18, 2005
    #2
    1. Advertising

  3. Thanks for the swift response Steve. We have implemented for comments with
    mixed response.

    I set access to anonymous for the Type and Node XML files and the Web
    Control will parse them and generate a correct browser html page. This
    works for me, ONLY if I reference the
    xml files in the HTML code itself as:
    <iewc:treeview id="TreeView1"
    TreeNodeSrc="XMLSafe.xml"
    TreeNodeTypeSrc="NodeType.xml" {other attributes here}... />

    I fail however when I attempt to use Page_Load using either of:

    TreeView1.TreeNodeSrc=Server.MapPath("xmlsafe.xml");
    TreeView1.TreeNodeTypeSrc=Server.MapPath("NodeType.xml");
    this.TreeView1.DataBind();

    or

    TreeView1.TreeNodeSrc="xmlsafe.xml";
    TreeView1.TreeNodeTypeSrc="NodeType.xml";
    this.TreeView1.DataBind();

    In both cases no exception is generated but the output (browser) html page
    contains no nodes and no node types! I know the page_event is wired
    correctly because I am also coding:

    TreeView1.Attributes.Add("onselectedindexchange",TreeView1.ClientID+"_onchan
    ge();");

    in the page_load event and this line is working as expected.

    I must have some other setting wrong? if i use invalid file names for the
    xml files I generate no exception?! (I am step debugging through this so I
    know the lines are being executed). Is the call to DataBind insufficient?

    thanks.

    dlr




    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Dennis,
    >
    > Welcome to ASPNET newsgroup.
    > From your description, it seems that you've encoutered an existing problem
    > of the IE webcontrol. When we use the TreeNodeSrc to specify a xml data
    > source, we need to configure the xml file (or the entire Virutal DIR) as
    > allow Anonymous.
    >
    > In addition, we can also resolve the problem by specifying the
    > "TreeNodeSrc" via physical file path , for example:
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > this.TreeView1.TreeNodeSrc = Server.MapPath("./treebooks.xml");
    > this.TreeView1.DataBind();
    > }
    >
    > set the treenodesrc at runtime via code. Hope helps.
    >
    > Thanks & Regards,
    >
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
     
    Dennis Redfield, Feb 18, 2005
    #3
  4. Hi Dennis,

    Seems a bit strange. Then, have you tried another means in my last message :

    Enable anonymouse asscess for that xml file and still set the TreeNodeSrc
    in the page inline?

    You can use this means to confirm that there hasn't been any other problem
    with your enviorment.

    In addition, as for the code you provided

    ======================
    TreeView1.TreeNodeSrc=Server.MapPath("xmlsafe.xml");
    TreeView1.TreeNodeTypeSrc=Server.MapPath("NodeType.xml");
    this.TreeView1.DataBind();
    =========================

    Call "DataBind" is necessary. And where is your aspx page and the
    xmlsafe.xml file? Are they in the same directory in your application or
    what's their location under your web app's root folder? I'm still thinking
    this should something with the path.
    BTW, you can try using the Server.MapPath("~/subfolder/filename")
    to reference the xml file since "~/" means from the application's root
    dir.

    HTH. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Feb 21, 2005
    #4
  5. Steve,

    Here is what is happening:

    I can successfully do the 'inline' method:
    >Then, have you tried another means in my last message :
    > Enable anonymouse asscess for that xml file and still set the TreeNodeSrc
    > in the page inline?


    Adding the xml data source dynamically within Page_Load is not happening
    correctly however.
    > TreeView1.TreeNodeSrc=Server.MapPath("xmlsafe.xml");
    > TreeView1.TreeNodeTypeSrc=Server.MapPath("NodeType.xml");
    > this.TreeView1.DataBind();

    this runs without any runtime error but no tree nodes are produced on the
    output html page.
    xmlsafe.xml is in the root of the web application (~/ now).
    I wired the DataBind event of TreeView1 and when I single step through the
    code in the debuger I can see that
    TreeNodeSrc is assigned and the call to the DataBind Method results in the
    DataBind event being fired, but it seems like dispite all this the xml file
    of nodes is NOT being bound correctly to the control?!?

    thanks in advance

    dlr


    "Steven Cheng[MSFT]" <> wrote in message
    news:QMKa6X%...
    > Hi Dennis,
    >
    > Seems a bit strange. Then, have you tried another means in my last message

    :
    >
    > Enable anonymouse asscess for that xml file and still set the TreeNodeSrc
    > in the page inline?
    >
    > You can use this means to confirm that there hasn't been any other problem
    > with your enviorment.
    >
    > In addition, as for the code you provided
    >
    > ======================
    > TreeView1.TreeNodeSrc=Server.MapPath("xmlsafe.xml");
    > TreeView1.TreeNodeTypeSrc=Server.MapPath("NodeType.xml");
    > this.TreeView1.DataBind();
    > =========================
    >
    > Call "DataBind" is necessary. And where is your aspx page and the
    > xmlsafe.xml file? Are they in the same directory in your application or
    > what's their location under your web app's root folder? I'm still thinking
    > this should something with the path.
    > BTW, you can try using the Server.MapPath("~/subfolder/filename")
    > to reference the xml file since "~/" means from the application's root
    > dir.
    >
    > HTH. Thanks,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
     
    Dennis Redfield, Feb 22, 2005
    #5
  6. Hi Dlr,

    I'm sorry to hear that the problem still remains.
    Have you tried creating another new web project and using the treeview in a
    simple page?
    Or if possible , you can also perform the sample test on some other box to
    see whether it also
    occurs.

    BTW, does "enable Allow Anoymouse" help ?

    If you feel necessary, I can also attached my test page and the TREEVIEW
    (ie wecontrol)'s assembly to you so that you can test on it on yoru side.

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Feb 23, 2005
    #6
  7. ok, steve. I will start a clean project and try again.
    and YES, YES setting the ACL to allow anoynemous access AND coding the xml
    file reference directly on the HTML attribute Works as advertised.

    thanks.

    dlr
    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Dlr,
    >
    > I'm sorry to hear that the problem still remains.
    > Have you tried creating another new web project and using the treeview in

    a
    > simple page?
    > Or if possible , you can also perform the sample test on some other box to
    > see whether it also
    > occurs.
    >
    > BTW, does "enable Allow Anoymouse" help ?
    >
    > If you feel necessary, I can also attached my test page and the TREEVIEW
    > (ie wecontrol)'s assembly to you so that you can test on it on yoru side.
    >
    > Thanks,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    >
     
    Dennis Redfield, Feb 23, 2005
    #7
  8. ok, Steve. Strange but true! I opened a new project and started fresh. NOW
    (?!) your code works correctly within the Page_Load event.

    thank you.!
    dlr
    "Dennis Redfield" <> wrote in message
    news:...
    > ok, steve. I will start a clean project and try again.
    > and YES, YES setting the ACL to allow anoynemous access AND coding the xml
    > file reference directly on the HTML attribute Works as advertised.
    >
    > thanks.
    >
    > dlr
    > "Steven Cheng[MSFT]" <> wrote in message
    > news:...
    > > Hi Dlr,
    > >
    > > I'm sorry to hear that the problem still remains.
    > > Have you tried creating another new web project and using the treeview

    in
    > a
    > > simple page?
    > > Or if possible , you can also perform the sample test on some other box

    to
    > > see whether it also
    > > occurs.
    > >
    > > BTW, does "enable Allow Anoymouse" help ?
    > >
    > > If you feel necessary, I can also attached my test page and the TREEVIEW
    > > (ie wecontrol)'s assembly to you so that you can test on it on yoru

    side.
    > >
    > > Thanks,
    > >
    > > Steven Cheng
    > > Microsoft Online Support
    > >
    > > Get Secure! www.microsoft.com/security
    > > (This posting is provided "AS IS", with no warranties, and confers no
    > > rights.)
    > >
    > >
    > >

    >
    >
     
    Dennis Redfield, Feb 23, 2005
    #8
  9. Thanks for your followup Dennis,

    Seems there has something incorrect in your former projects. Anyway, glad
    that nothing wrong with your ASPNET environment and you got it work again.
    Also, if you meet any further problem later, please feel free to post here.

    Thanks & Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Feb 25, 2005
    #9
    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. Replies:
    0
    Views:
    2,081
  2. =?Utf-8?B?bWFya2FlbGtpbnNAbmV3c2dyb3Vwcy5ub3NwYW0=

    How to enter a variable in the treenodesrc of a treenode

    =?Utf-8?B?bWFya2FlbGtpbnNAbmV3c2dyb3Vwcy5ub3NwYW0=, Sep 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    1,076
    Steven Cheng[MSFT]
    Sep 19, 2005
  3. Guest

    Set TreeNodeSrc to an XML file dynamically ???

    Guest, Sep 29, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    170
    Tian Min Huang
    Sep 29, 2003
  4. Thomas
    Replies:
    1
    Views:
    237
    Rajesh.V
    Oct 16, 2003
  5. ThoGen
    Replies:
    0
    Views:
    121
    ThoGen
    Apr 21, 2006
Loading...

Share This Page