Solved

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

Posted on 2009-05-04
1
587 Views
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\")))
            {
                Directory.CreateDirectory(@"C\PROD_CI\");
            }
            strPath = @"C\PROD_CI\" + strFile;
            objFSO = new FileInfo(strPath);
            if (objFSO.Exists)
            {
                objFSO.Delete();
            }
             createStatFileReturn = objFSO.CreateText();
             objFSO = null;
              return createStatFileReturn;
}
 
public static void PrintFile(ref StreamWriter objFSOFile, string strData)
{
       objFSOFile.WriteLine(strData);
}

Open in new window

0
Comment
Question by:MPakeezah
1 Comment
 

Accepted Solution

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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

778 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