user2276352
user2276352

Reputation: 91

How do I convert a string array(having xml content) into an XML file?

I am storing the string array content into a txt file and then trying to change the extension of the txt file to xml so as to make it read using XDocument.

Now the problem is that when I am trying to change the extension using the Path.ChangeExtension method, it isn't changing the extension.

I have a task of sending data using WCF by only using string messages and I want to send an XML file. So I am dumping the XML file content into a string array and sending it over to the client. But my client is only able to read from XML file and that is the reason that I am trying to convert the string array into an XML file.

Also, the XML's structure is always going to be the same in every communication and of course only the data is going to change.

Please help me figure out how I can implement this.

Upvotes: 2

Views: 142

Answers (1)

Henk Holterman
Henk Holterman

Reputation: 273244

The Path.ChangeExtension() method just produces a string, it won't change anything on disk.

Use the result with File.Rename :

string newFilename = Path.ChangeExtension (oldFilename , ".xml");
File.Move(oldFilename , newFilename );

Upvotes: 1

Related Questions