views:

2128

answers:

2

I have an ASHX handler that returns an XML response (FileStructureXML.ashx).

Now I need to get the XML response from the ASHX handler and use it as a data source for my ASPX page.

If I point the XMLDataSource to a static XML file on the server, the treeview populates as expected. However, if I point the XMLDataSource to the ASHX handler instead of a static XML file on the server, it doesn't work.

Any help would be appreciated.

<body>
    <form id="form1" runat="server">
    <div>

        <asp:TreeView ID="TreeView_Folders" runat="server" DataSourceID="FileXML">
            <DataBindings>
                <asp:TreeNodeBinding DataMember="Directory" TextField="Name" />
                <asp:TreeNodeBinding DataMember="File" TextField="Name" />
            </DataBindings>        
        </asp:TreeView> 
    </div>
    <div>
        <asp:XmlDataSource ID="FileXML" runat="server" DataFile="FileStructureXML.ashx">
        </asp:XmlDataSource>
    </div>
    </form>
</body>
+2  A: 

I think that the XmlDataSource only works with an actual file, not a URL. You might be able to work around this by not specifying a DataFile property and loading the Data property dynamically in your code behind. I think the FirstChild.OuterXml selection is correct, but you may need to experiment. I'm not in a place where I can test it.

XmlDocument treeDoc = new XmlDocument();
treeDoc.Load( "~/FileStructureXML.ashx" ); // this takes a URL
FileXml.Data = treeDoc.FirstChild.OuterXml; // everything after the xml definition
tvanfosson
A: