Bah, answer was right there.... The HTML page was created from an xsl from the client. The html itself is marked <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
FF Listens, IE does not. Bah! At least it is fixed now. Thanks, Jon -----Original Message----- From: Jonathan Heizer [mailto:[EMAIL PROTECTED] Sent: Monday, October 16, 2006 3:34 PM To: 'Discussion of advanced .NET topics.' Subject: RE: [ADVANCED-DOTNET] Writing UTF8 File Problems Well, I switched back to using the streamwriter like this: writer = New IO.StreamWriter(Filename, False, Text.Encoding.UTF8) writer.Write(TempHTML) writer.Flush() writer.Close() The file now shows up as UTF8 in programs like Notepad++ and others. IE is able to open this file correctly, but FF is having problems. Since I always use FF I just happened to open it in IE and see that it worked. If you right click and select Properties in the FF window it says the encoding is ISO-8859-1 and a Google tells me this is Latin-1. Not going to help in displaying Chinese. If I go to one of my ASP.Net pages from another project that displays Chinese properly FF lists it as UTF-8. I deleted a bunch of the junk in one of these files and posted it at http://vissystems.com/utf8.html It should open correctly in IE, but not in FF. -Jon -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Adam Sills Sent: Monday, October 16, 2006 2:45 PM To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] Writing UTF8 File Problems The *data* you're writing to the file is indeed UTF8 encoded, however your file needs a BOM (Byte Order Mark) to indicate that it is a UTF8 file. By calling GetBytes on a string, you will not get a BOM in the returned set of bytes. This is why VS2005 doesn't recognize it as a UTF8 file; the file doesn't contain the UTF8 header (BOM). Using a StreamWriter is the correct approach, but if you're using a "new UTF8Encoding()" you won't get the BOM in the output. Look in MSDN at the UTF8Encoding constructor and notice the default encoding indicates "This constructor creates an instance that does not provide a Unicode byte order mark and does not throw an exception when an invalid encoding is detected". What you should use instead is the static Encoding.UTF8 property to get a reference to the default UTF8 encoding object, which does provide a BOM. Then use a StreamWriter, specifying Encoding.UTF8 as the encoding, and write out your text and it will populate the file with a BOM. Next read this article: http://www.joelonsoftware.com/articles/Unicode.html It talks about Byte Order Marks (and other encoding stuff). Adam.. -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Jonathan Heizer Sent: Monday, October 16, 2006 2:02 PM To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: [ADVANCED-DOTNET] Writing UTF8 File Problems I have a process that writes out a html file in various languages. I need this file to be in UTF8 format, but it is not cooperating. I read in translated text from a UTF8 xml file and combine it with html and formatting in code. I use the following to write out the file. UTF8File = New FileStream(FileName, FileMode.Create) Bytes = New Text.UTF8Encoding().GetBytes(TempHTML) UTF8File.Write(Bytes, 0, Bytes.Length) UTF8File.Flush() UTF8File.Close() I have also tried using a StreamWriter and setting the encoding to UTF8 in the constructor and was left with the same results. If I open it in VS05, mark it as utf8, and save it the encoding is corrected. Any ideas? =================================== This list is hosted by DevelopMentor. http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com