I followed this topic, but I got an unhandled Exception (UnauthorizedAccessException
) at this line: Stream file = File.Open(filename, FileMode.Create)
.
Edit: Here's my code:
public void SaveTree(TreeView tree, string filename)
{
using (Stream file = File.Open(filename, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(file, tree.Nodes.Cast<TreeNode>().ToList());
}
}
SaveTree(treeView1, path); //in the SaveButton_Click method
Is someone can help me?