Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
WebServiceOutput wso = new WebServiceOutput();
BinaryWriter binWriter = new BinaryWriter(File.Open(@"C:\DAF\config\xyz.xml", FileMode.Create, FileAccess.Write));
binWriter.Write(HierarchyFileContent);
binWriter.Close();



Let me know, When i am trying to create new xml file using "FileMode.Create". File will be saved in a single line not in appropriate from.
Posted
Comments
Sergey Alexandrovich Kryukov 13-Mar-15 1:55am    
There is nothing wrong with that. But the question makes no sense, because what happens just depends on HierarchyFileContent; you did not bother to show how it is initialized (I am not curious to know).
—SA
Harry226208 13-Mar-15 4:35am    
Let me know why xml save in a single line.
Any other solution to set in a proper format.
Sergey Alexandrovich Kryukov 13-Mar-15 8:46am    
Because HierarchyFileContent is one line. How can I know what's in it.
—SA
Richard MacCutchan 13-Mar-15 4:50am    
Probably because you are using a BinaryWriter. Use one of the builtin XML writer classes.
Sergey Alexandrovich Kryukov 13-Mar-15 8:47am    
No, not because of that. Binary writer would write the data as it is, with all line ends (which, by the way, depend on the platform).
—SA

1 solution

You can achieve the properly formatted XML string by loading it into an XDocument and then just calling ToString on it:
C#
WebServiceOutput wso = new WebServiceOutput();
BinaryWriter binWriter = new BinaryWriter(File.Open(@"C:\DAF\config\xyz.xml", FileMode.Create, FileAccess.Write));

// Prettify (indent) 'HierarchyFileContent' content.
binWriter.Write(XDocument.Parse(HierarchyFileContent).ToString());
binWriter.Close();
 
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