Click here to Skip to main content
15,896,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all..

actuually wat happend means..i create sample folder in 'D' and in that i created SAMPLE FOLDER ,again i created HELLO FOLDER and one .txt file, in that HELLO FOLDER i created two .txt files..
in that code i take default path like "D:\sample" the above entire directory structure displayed like as a string..
string is like this: abc.txt hello xyz.txt pqr.txt..
now i want to serilaize the entrire directory structure and i want the output like this:
{"Root":"d:\\"{"mainfolder":"sample","mfile":"abc.txt","subfolder":"hello"{"hfile1":"xyz.txt","hfile2":"pqr.txt"}}}..
if any body knows pls let me know..
thanks in advance..
Posted
Updated 8-Aug-11 1:26am
v2
Comments
RaisKazi 5-Aug-11 4:56am    
Question is unclear. You can serialize an Object of some Type into JSON/XML formated string.
RaisKazi 5-Aug-11 4:57am    
What exactly you are trying to achieve?
komalilella 5-Aug-11 5:02am    
actuually wat happend means..i create sample folder in 'D' and in that sample folder again i create hello folder and in that hello folder i created one .txt file.by using i displayed as a string in textbox i got string like this:
D:\sample\hello\text.txt.now iam doing how to serialize that path in json..
this my task..
pls let me know,if u have soluution..
RaisKazi 5-Aug-11 5:05am    
Wait. I guess you want to show text of your "text.txt" file in some TextBox. Is my guess correct?
komalilella 5-Aug-11 5:13am    
no..
i want entire folder structure path as string in textbox..

You don't really need to do anything manually. Instead, use Data Contract with System.Runtime.Serialization.Json.DataContractJsonSerializer.

See:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^],
http://msdn.microsoft.com/en-us/library/bb412179.aspx[^]
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx[^].

Please also see my past solution where I advocate this robust and easy-to-use approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^].

I explain things using System.Runtime.Serialization.Json.DataContractSerializer (http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx[^]), but this is applicable to System.Runtime.Serialization.Json.DataContractJsonSerializer as well.

—SA
 
Share this answer
 
Check out fastJSON[^] for the JSON part.
And look at DirectoryInfo Class[^] and FileInfo Class[^] for folder and file info.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900