Using the StreamWriter to write a UTF-8 encoded XML file

RoyFripple

New member
Joined
Dec 5, 2005
Messages
1
Location
Wisconsin
Programming Experience
1-3
In the program I'm working on, I need to transform an XML file using an XSLT and then write it to a file. I've got the transformation part down fine, but my problem lies in the creation of the file.

I'm using this to create my file:

Dim sw As StreamWriter = File.CreateText(strLocalFile)

Now this works fine, I can even write the string created from the transform to the file. The problem is that it's encoding it as UTF-16 and I need it to be in the UTF-8 encoding.

My question is whether there is anyway to get it to create the file with UTF-8 encoding instead of 16.

Thanks!
 
Last edited:
File.CreateText methods return value is a StreamWriter that writes to the specified file using UTF-8 encoding. You can also use one of the overloaded constructors of StreamWriter class to output with different encodings.
 
Back
Top