I have a treeview and I want to export treeview parent nodes, child to .txt file. but when I export .txt file the format looks very bad. I found this topic but its not helpful for me. There is a another way ?
Saving content of a treeview to a file and load it later
I want to like this in .txt file
- Main Folder
- Sub Folder
- .docx or .zip file
- .docx or .zip file 2
- Sub Folder 2
- .txt file
- Sub Folder
but in my .txt file like this.
ÿÿÿÿ WSystem.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ›System.Collections.Generic.List`1[[System.Windows.Forms.TreeNode, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] _items_size_version System.Windows.Forms.TreeNode[] System.Windows.Forms.TreeNode
System.Windows.Forms.TreeNode TextToolTipTextName IsChecked
ImageIndexImageKeySelectedImageIndexSelectedImageKey
ChildCount children0 children1 children2 children3 children4 children5 children6 children7 children8 children9
children10
children11
children12
children13
children14
children15
children16
children17
children18
children19
children20
children21UserData System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode +ASP .NET MVC Yazılımcıların Yükselişi
IC:\Users\asd\Desktop\ASP .NET MVC Yazılımcıların Yükselişi System.Windows.Forms.TreeNode TextToolTipTextName IsChecked
ImageIndexImageKeySelectedImageIndexSelectedImageKey
ChildCount children0 children1 children2 children3 children4UserData System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode System.Windows.Forms.TreeNode 1-ASP.NET MVC GiriÅŸ ! " # $ % ^C:\Users\asd\Desktop\ASP .NET MVC
this my code
public static void SaveTree(TreeView tree, string filename)
{
using (Stream file = File.Open(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\myFile.txt.", FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(file, tree.Nodes.Cast<TreeNode>().ToList());
}
}