Replace string in XML file

Richard Kreidl
Richard Kreidl used Ask the Experts™
on
How would I replace the first line in a XML file?

Current string = <?xml version="1.0" standalone="yes"?>
Desired string = <?xml version="1.0" encoding="utf-8"?>

I tried using the replace command but I get error because of the question character in the string.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try using the File Class in the System.IO library.

Imports System.IO
Dim FileName As String = "MyPath\MyFile"
Dim FileLines() As String = File.ReadAllLines(FileName)
FileLines(0)="<?xml version=""1.0"" encoding=""utf-8""?>"
File.WriteAllLines(FileName,FileLines)

Open in new window

Richard KreidlSoftware Developer

Author

Commented:
thanks!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial