2

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.

1
  • who's creating the .txt-file, and how big is your xml-data? Commented Nov 12, 2013 at 19:47

1 Answer 1

1

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 );
Sign up to request clarification or add additional context in comments.

3 Comments

Ah, I see! Then how do I change the extension on the disk? Or is there any other possible solution to my problem?
Thank you for your response. Still, I am facing a problem. The name of my file is "OCD1.txt" and with this name the File.Move won't work. But when I am changing the file name to only"OCD1", this is working.
Strange. Be sure to test that again, thoroughly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.