Appeldapese
New Member
Posting both question and (one) answer here to see if somebody has a better solution...I am trying to write formatted XML output from stored procedure to file. My first attempt looked like this:\[code\]// the actual command is a stored procedure that returns an XML document, but use this for demo purposesvar xmlCommand = new SqlCommand("SELECT 1 as ID, 'asdf' as Name FOR XML PATH, ROOT('MyData')", conn);File.WriteAllText("file1.xml", (string)xmlCommand.ExecuteScalar());\[/code\]Which was nice and short, but the file generated has everything stuffed on one line:\[code\]<MyData><row><ID>1</ID><Name>asdf</Name></row></MyData>\[/code\]I want it to be formatted nicely:\[code\]<MyData> <row> <ID>1</ID> <Name>asdf</Name> </row></MyData>\[/code\]