Represent directory structure as data structure of your choice and use the class
System.Runtime.Serialization.Json.DataContractJsonSerializer
. Use appropriate attributes in data type(s), such as
DataContract
and
DataMember
, to define a
Data Contract. It will help you to store any object graph and restore it back using JSON file/stream for persistent storage. You won't need to program persistence manually in any way which will make your implementation extremely simple and robust.
See:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx[
^],
http://msdn.microsoft.com/en-us/library/ms733127.aspx[
^].
Please also see my past answer where I advocate using Data Contracts:
How can I utilize XML File streamwriter and reader in my form application?[
^],
Creating a property files...[
^],
deseralize a json string array[
^].
First two of my answers are about
System.Runtime.Serialization.Json.DataContractSerializer
but are also applicable to
System.Runtime.Serialization.Json.DataContractJsonSerializer
.
—SA