473,698 Members | 2,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing TreeView Contents To XML

I am writing an RSS reader in C# and I'm trying to write the contents
of a TreeView to an XML file. I have tried using XmlWriter and have
managed to write simple tree structures but I get confused when it
comes to dealing with complex tree structures such as those that have
multiple folders and sub folders.

I have tried searching Code Project and the Net but haven't had much
joy in finding a solution. I have only been using C# for a few months
and my programming knowledge is fairly limited.

Is XmlWriter the best way to write out a TreeView? How would you go
about going through each of the folders and writing the feeds within
them?

If there is anything else that I need to include let me know.
Nov 16 '05 #1
5 9957
Robert Gale wrote:
I am writing an RSS reader in C# and I'm trying to write the contents
of a TreeView to an XML file. I have tried using XmlWriter and have
managed to write simple tree structures but I get confused when it
comes to dealing with complex tree structures such as those that have
multiple folders and sub folders.

Is XmlWriter the best way to write out a TreeView? How would you go
about going through each of the folders and writing the feeds within
them?


you might want to start with learning how to traverse a tree:

http://www.brpreiss.com/books/opus5/html/page259.html
Nov 16 '05 #2
Thanks for the quick reply. I am familiar with ways of traversing a tree
I'm just not familiar with how to write code to do so using XmlWriter.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Hi ,

Nothing less here is a more closer answer...

I just took it from one of my old code, carefully go through this I can even
give the full code to you.. it has both write and read facility but for a
customized treenode object...

//Starting here.......
// Call the procedure using the TreeView.
private void CallRecursive()
{
str = File.CreateText ("My.xml");
myData = "";
// browse each node recursively.
TreeNodeCollect ion nodes = treeView1.Nodes ;
foreach (TreeNode n in nodes)
{
BrowseRecursive (n, ref myData);
}
str.Write(myDat a);
str.Close();
}

private void BrowseRecursive (TreeNode treeNode, ref string myStr)
{
// browse each node recursively.

if (treeNode.Nodes .Count >0)
myStr += "<" + treeNode.Text + ">";
else
myStr += treeNode.Text;
foreach (TreeNode tn in treeNode.Nodes)
{
BrowseRecursive (tn, ref myStr);
}
if (treeNode.Nodes .Count >0)
myStr += "</" + treeNode.Text + ">";
}

Regards,
Nirosh.

"Robert Gale" <ro*****@gmail. com> wrote in message
news:16******** *************** ***@posting.goo gle.com...
I am writing an RSS reader in C# and I'm trying to write the contents
of a TreeView to an XML file. I have tried using XmlWriter and have
managed to write simple tree structures but I get confused when it
comes to dealing with complex tree structures such as those that have
multiple folders and sub folders.

I have tried searching Code Project and the Net but haven't had much
joy in finding a solution. I have only been using C# for a few months
and my programming knowledge is fairly limited.

Is XmlWriter the best way to write out a TreeView? How would you go
about going through each of the folders and writing the feeds within
them?

If there is anything else that I need to include let me know.

Nov 16 '05 #4
Great! This could be what I was looking for. I'll give this a try this
morning and let you know how I get on.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
Thanks Nirosh. Your code was a great help. With a little tweaking I was
able to change it for my needs.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1541
by: T.H.M | last post by:
This is the all code. Very simple and short. I need to populate a treeView in aspx page (web form) from XML file. I get en completion error:No overload for method 'TreeNode' takes '1' arguments . using System; using System.Web.UI.WebControls; using Microsoft.Web.UI.WebControls; using System.Xml;
1
3635
by: Casper JH Erasmus | last post by:
How do I save the contents of a TreeView to a XML Document?
7
11104
by: Mike | last post by:
hi everyone! i'm searching for a tutorial or an example for how to fill a treeview with information from my ms sql database. i've found some on "code project" and other sites, but nothing like a real tutorial for beginners. does anyone knows some helpflul links or can give me a short intro? my treeview should act like a navigator or explorer-like, so that a click on a node shows some detailed information on the right side of my win app....
7
2832
by: vsiat | last post by:
I am trying to create a treeview out of a database table with the typical structure ID, NAME, PARENTID, TYPE, EXTRA_INFO, where is linked to the . What I want to achieve is create a tree made of custom, extended nodes, which include all the extra information contained in the table and not just typical TreeNode objects. To do that, I first created a structure with all the extra
14
15091
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
0
1466
by: stardust | last post by:
Hi everyone, Within a Winform application, a treeview is contained in a User Control and the User Control is then located within a splitview. When the UserControl added some nodes into the Treeview, the treeview is not displaying the added nodes, it just keep displaying the initial node added to it during initallisation. Tried variious method like TreeView.Invalidate() and TreeView.Update(). The code which adds nodes to the treeview is...
1
1956
by: David | last post by:
Help!!! // // Contents of ValueNode.cs // using System; using Microsoft.Web.UI.WebControls;
1
2305
by: Dan Bass | last post by:
Using: ASP.Net 2.0 C# for code behind I'm slowly migrating a project into the .Net realm from ASP. One of the first things I've been asked to do is replace a tree navigation control (java applet), with the ASP.Net TreeView. The tree resides in a frame, and when a link is clicked, has to change the HREF of another frame. Currently, the applet calls some javascript
2
2597
by: Simon Rigby | last post by:
Hi folks, A bizarre problem I am having. I have a treeview which is bound to an XmlDataSource. The XMLDataSource.Data property is set to the result of a function that generates an XML document from a SQL Query. The problem is that the Treeview renders correctly and expands with the appropriate hierarchy but clicking anything but the very top node gives me a NULL Reference Exception. I haven't even got to the stage of doing anything...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.