Posts

Showing posts from November, 2016

XML to String with UTF-8 encoding

Was having some issues trying to post with some xml data in utf-8 format, since it kept coming out in utf-16 even though I would set the contenttype and other settingsand somehow ignoring them.  I found an article that gave me a solution where they create a class that overrides the encoding of the string writer to utf-8 and that worked. ......  Dim sb = New StringBuilder()             Using writer As StringWriter = New StringWriterUtf8(sb)                 xmlDoc.Save(writer)             End Using             Return sb.ToString() ....... then in a class    Public Class StringWriterUtf8         Inherits StringWriter         Public Sub New(sb As StringBuilder)             MyBase.New(sb)         End Sub         Public Overrides ReadOnly Property Encoding() As Encoding             Get                 Return Encoding.UTF8             End Get         End Property     End Class ....... http://rlacovara.blogspot.com/2011/02/how-to-create-xml-in-c-with-utf-8.html