473,322 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 9933
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.
TreeNodeCollection nodes = treeView1.Nodes;
foreach (TreeNode n in nodes)
{
BrowseRecursive(n, ref myData);
}
str.Write(myData);
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.google.c om...
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
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 ....
1
by: Casper JH Erasmus | last post by:
How do I save the contents of a TreeView to a XML Document?
7
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...
7
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...
14
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
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...
1
by: David | last post by:
Help!!! // // Contents of ValueNode.cs // using System; using Microsoft.Web.UI.WebControls;
1
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...
2
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.