question

JERRYWarra-9978 avatar image
0 Votes"
JERRYWarra-9978 asked DanielZhang-MSFT answered

Populate treeview based on xml, but check attribute if it should display

I have an internal website that has 2 similar pages that will display some of the same documents and some that are page specific.

Is it possible to populate a treeview based on the XML file where 2 attributes are that indicate Y/N if that node should be displayed on that page?


  <docs>
     <doc Text="Data1" p1="Y" p2="N">
         <file Text="Name" p1="Y" p2="N">
             <type p1="Y" p2="N" text="PDF" url="www.data1.tmp" />            
         </file>
     </doc>
     <doc Text="Data2" p1="N" p2="Y">
         <file Text="Name" p1="N" p2="Y">
             <type p1="N" p2="Y" text="docx" url="www.data2.tmp" />            
         </file>
     </doc>
     <doc Text="Data3" p1="Y" p2="Y">
         <file Text="Name" p1="Y" p2="Y">
             <type p1="Y" p2="Y" text="txt" url="www.data3.tmp" />            
         </file>
     </doc>    
 </docs>

PAGE 1

Data1
..Name
....PDF *Link using URL attribute
Data3
..Name
....txt *Link using URL attribute


PAGE 2

Data2
..Name
....docx *Link using URL attribute
Data3
..Name
....txt *Link using URL attribute



I want to be able to update the XML file and have the trees rendered based on the XML file. I don't want to have to include and exclude in the code behind every time a new document is added.

Thank you for any help







dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered

Hi JERRYWarra-9978,
You can try to use linq xml to populate treeview from XML.
Code looks like:

 var data = XElement.Load(source.xml);
 foreach (XElement single in data.Elements())
 {
   treeNode.Nodes.Add(single.Element("name of element").Value);
 }

Moe details you can refer to this thread.
Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.