Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, June 9, 2008 8:03 AM
Hi,
I have a form which displays some on-the-fly created HTML content in a WebBrowser. But the thing is that I can not make Turkish characters look good. If I manually open the same HTML document in the IE it displays the correct encoding but always fails in the WebBrowser. The images are:
[Link to images]
I have added combinations of the following
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1254" />
<meta http-equiv="Content-Language" content="tr" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
in the HTML files and also tried the
browser.Document.Encoding = "iso-8859-9";
browser.Document.Encoding = "windows-1254";
browser.Document.Encoding = "UTF-8";
lines in the page where I display the content but still the characters encoding problem exists. Any help on the issue please?
Regards.
Utku Ozan ÇANKAYA
All replies (4)
Monday, June 9, 2008 4:24 PM ✅Answered
By using ICscHostObject.SetCodePage Method you can let your computer know that it will have all input / output from now on formatted in your particular culture. Let's say you have French keyboard with all those funny accents but the OS is English speaking, then when you type your character internally it is doing fine, it won't be los anywhere because it is just code but when it come to displaying it to the user and also getting input from him this is where you will get all those what you call garbage.
The above message is at this link:
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_microsoft.build.tasks/html/43633758-d552-cbff-acef-92e8183f37a8.htm
It is in Microsoft.Build.Tasks.Hosting namespace.
Also take a look at:
Encoding.CodePage Property
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_mscorlib/html/dc9e591e-1cae-95f9-6773-1582fcd4fb4d.htm
Your codePage you can find at this link:
CultureInfo Class
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_mscorlib/html/63c619e3-0969-2f01-a2d4-79d0868a98c6.htm
For en-US it is 1033 or 0x0409
For French-France: 1036 or 0x040C
For Spanish-Mexico: 2058 or 0x080A
AlexB
Monday, June 9, 2008 3:35 PM
I think most known Turkish problems can be fixed with VS2005/8 advanced save as option which let you save your code as Turkish.
An Elliptic curve is modular ~ Taniyama and Shimura
Tuesday, June 10, 2008 7:24 AM
I think the main issue was about using the codepage. Previously I was using such code:
| 1 | string currPath = Directory.GetCurrentDirectory(); |
| 2 | if (File.Exists(currPath + "\\duyuru.htm")) |
| 3 | { |
| 4 | File.Delete(currPath + "\\duyuru.htm"); |
| 5 | } |
| 6 | |
| 7 | TextWriter tw = new StreamWriter(currPath + "\\duyuru.htm"); |
| 8 | tw.WriteLine(ds.Tables[0].Rows[i]["DuyuruMetin"].ToString()); |
| 9 | tw.Close(); |
But it was impossible to set the codepage with this method. I also have tried inserting code page definitions to HTL document and tried to set the Encoding of the HTMLBrowser object, but this one also failed because that the property was read-only.
But after, I realized that it will be more logical to set the encoding while creating the document, not displaying it. So I have updated the code as follows:
| 1 | string currPath = Directory.GetCurrentDirectory(); |
| 2 | if (File.Exists(currPath + "\\duyuru.htm")) |
| 3 | { |
| 4 | File.Delete(currPath + "\\duyuru.htm"); |
| 5 | } |
| 6 | using (StreamWriter sw = new StreamWriter(currPath + "\\duyuru.htm", false, Encoding.UTF8)) |
| 7 | { |
| 8 | sw.Write(ds.Tables[0].Rows[i]["DuyuruMetin"].ToString()); |
| 9 | sw.Close(); |
| 10 | } |
I finally managed to make the whole thing work as it should be. Thank you very much for your help and interest.
Regards.
Utku Ozan ÇANKAYA
Friday, September 2, 2011 8:53 AM
Hi Utku Ozan,
I have the same problem with you, I read your solution but couldn't understand. What can I do to solve this problem? Help pls.
Thanks.