Monday, April 25, 2011

French letters on an aspx page

I have a winForm application that generates an .aspx file based on the user input in the application. The problem happens when a user enters the French letters like "é", "à", "è", "â", "ù", "ô", "ê" and "ç". It is supposed to look like a simple text on the page but it doesn't. Any ideas?

From stackoverflow
  • What does the text look like? Have you ensured the encoding type supports extended characters?

  • Assuming you want the characters to be displayed with the accents, circumflexes, etc. try the following:

    Add the following to the <head> of each (generated) page:

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    

    Make sure that the .aspx files themselves are saved as UTF-8 files.

    Note: I'm assuming here that an .aspx file is somewhat similar to a .jsp file. If that assumption is false, you should probably ignore this advice.

    Ivan : I was constantly trying that meta tag with charset=UTF-8, but haven't set the encoding of my textWritter, like you and the others suggest. So I think that TextWriter tw = new StreamWriter("Default.aspx", false, Encoding.UTF8); will do the trick.
  • How are you creating the .aspx file? If you're using a TextWriter, check the Encoding. If you're trying to write an array of bytes to a FileStream, be sure you use the right encoding when converting from String to Byte[]. UTF-8 is usually the best encoding for the web.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.