how to write special characters to an excel file in C#.Net

Posted on 2009-05-04
Last Modified: 2012-05-06
I have a text which contains special Characters: "création des motifs"
I need to write this to an excel file. This is not being written correctly.
Can anyone please help...
StreamWriter objFSOFile = null;

string strData = null;

string strPath = null;

objFSOFile = CreateStatFile("PROD.CSV", ref strPath);

strTitle = "création des motifs";

PrintFile(ref objFSOFile, strTitle);

public static StreamWriter CreateStatFile(string strFile, ref string strPath)


       System.IO.StreamWriter createStatFileReturn = null;

       FileInfo objFSO = null;

        if (!(Directory.Exists(@"C\PROD_CI\")))




            strPath = @"C\PROD_CI\" + strFile;

            objFSO = new FileInfo(strPath);

            if (objFSO.Exists)




             createStatFileReturn = objFSO.CreateText();

             objFSO = null;

              return createStatFileReturn;


public static void PrintFile(ref StreamWriter objFSOFile, string strData)




Open in new window

Question by:MPakeezah
1 Comment

Accepted Solution

MPakeezah earned 0 total points
Comment Utility
The solution is while creating the file itself, create it as encoding UTF8.
createStatFileReturn = new StreamWriter(objFSO.Create(), System.Text.Encoding.UTF8);

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now