Reputation: 275
I have XML content that I am retrieving from a service and I want to write it into a text file. I am getting this XML content in a string variable.
How can I read this and write in text file? Please help. I am getting data successfully using this code:
string results = "";
using (WebClient Web = new WebClient())
{
results = Web.DownloadString(WebString.ToString());
}
I have tried some links, but they are not helping
Upvotes: 1
Views: 3055
Reputation: 1500515
If you want to save it in a file, don't use DownloadString
to start with - just use WebClient.DownloadFile
.
If you really want to fetch it in memory and then save it, you can save it with:
File.WriteAllText(filename, results);
Note that this code doesn't depend on it being XML at all... nothing you're asking is XML-specific.
Upvotes: 1