LoadContentFile from URL

2 posts, 0 answers
  1. Jerry
    Jerry avatar
    49 posts
    Member since:
    Mar 2012

    Posted 12 Oct 2020 Link to this post

    Hello,

     

    Is it possible to populate a TreeView control from an XML file that is on another web server?

    I'm using the LoadContentFile to load the tree on the website where the XML file is located, but I'm not sure how to populate the TreeView on my other website that needs the same source.

    I'm using the XML file on 2 different websites and wanted to use the one source. 

    I currently get "is not a valid virtual path" error.

    This is an example URL: https://temp.com/xml/temp.xml

    Thank you

  2. Vessy
    Admin
    Vessy avatar
    2369 posts

    Posted 15 Oct 2020 Link to this post

    Hi Jerry,

    The implementation of the LoadContentFile() is based on the Context.Server.MapPath() method and as such can work only with virtual paths to files placed inside the application's root directory.

    		public virtual void LoadContentFile(string xmlFileName)
    		{
    			string xml = File.ReadAllText(Context.Server.MapPath(xmlFileName));
    			LoadXml(xml);
    		}

    If you have access to the file content from the page holding the TreeView, though, you can pass the xml data directly through the control's LoadXml method:
    https://docs.telerik.com/devtools/aspnet-ajax/controls/treeview/data-binding/loading-xml-content#loading-from-an-xml-string

    RadTreeView1.LoadXml("<Tree><Node Text="Books"/><Node Text="Music"/></Tree>");

    Regards,
    Vessy
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Back to Top