Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

characters with accent sor umlauts get written wrong

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Dalberg - 15 Feb 2006 16:00 GMT
I am using the code snippet below. If the datagrid displays words with
french accent 'e' like 'cafe' or 'Toshiba Protege', the file test.xls
displays these e's as garbled 3 characters.

Do I need to do some formatting or specify some code page, langauge..etc?

                               StreamWriter sr;
                               StringWriter sw = new StringWriter();
                               HtmlTextWriter htw = new
                               HtmlTextWriter(sw);
                               myDataGrid.RenderControl(htw); sr =
                               File.CreateText("test.xls");
                               sr.WriteLine(sw.ToString());

John Dalbeg
Joerg Jooss - 17 Feb 2006 19:00 GMT
Thus wrote John,

> I am using the code snippet below. If the datagrid displays words with
> french accent 'e' like 'cafe' or 'Toshiba Protege', the file test.xls
> displays these e's as garbled 3 characters.
>
> Do I need to do some formatting or specify some code page,
> langauge..etc?

File.CreateText() uses UTF-8 as character encoding. It seems Excel (I'm using
2003 SP2) doesn't correctly decode such a file if it is simply opened by
double clicking. But if you open the file from within Excel, you can choose
the correct encoding and process the file successfully.

> StreamWriter sr;
> StringWriter sw = new StringWriter();
[quoted text clipped - 3 lines]
> File.CreateText("test.xls");
> sr.WriteLine(sw.ToString());

As a workaround, simply create your text file with a Windows specific encoding
(Windows-125x), usually exposed as Encoding.Default.

sr = new StreamWriter("test.xls", false, Encoding.Default);

If you can't use the default settings for file access applied by StreamWriter
internally, create a FileStream with your specific accesss flags set first,
and pass that to your StreamReader:

sr = new Streamwriter(fileStream, Encoding.Default);

Cheers,
Signature

Joerg Jooss
news-reply@joergjooss.de


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.