C# – How to write an XML string to a file


I have a string and its value is:

    <SampleElement2>The text of the sample element2</SampleElement2> 

How can I write this string to a file using C# 3.0?

Thanks in advance.

Best Solution

Try this:

string s = "<xml><foo></foo></xml>";
XmlDocument xdoc = new XmlDocument();

Has the added benefit that the load will fail if your XML is invalid.