Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Treeview to xml and vice versa

Anyone tried and succeeded in saving a populated treeview to XML (or as binary data) and succesfully rebuild the treeview from file?
And if so, how did you do that? With the standard serialization class?

I tried a lot but am lost in the .NET structured woods now and hope anyone can help me out here.

Thank you!

Jurgen
Friday, October 01, 2004

try:

private void Serialize()
{
    ArrayList nodeList = new ArrayList();

    FileStream fs = File.OpenWrite("tree.bin");

    BinaryFormatter bf = new BinaryFormatter();
    foreach (TreeNode node in (treeView1.Nodes))
    {
          nodeList.Add(node);
    }
    bf.Serialize(fs, treeView1);
    fs.Close();
}

private void Deserialize()
{

    FileStream fs = File.OpenRead("tree.bin");
    BinaryFormatter bf = new BinaryFormatter();
    treeView1.Nodes.Clear();
    treeView1.BeginUpdate();
    foreach (TreeNode node in (ArrayList) bf.Deserialize(fs))
    {
          treeView1.Nodes.Add(node);
    }
    treeView1.EndUpdate();
    fs.Close();
}


(from: http://perso.3ie.org/yannick.lejeune/archives/2004_05_01_blog-programmation-dotnet.html )

Just me (Sir to you)
Friday, October 01, 2004

*  Recent Topics

*  Fog Creek Home