RadhaKrishnaKiJaya
asked on
Special character is not displaying correctly
Hi Experts,
I have this code. When I export the data to CSV file, it should display "Approuvé Date".
But it is not encoding the "é " character properly and displaying "Approuvé Date".
Please help me what should I do to fix this problem. It happens for French, German and Italian language.
Thanks in advance!
using Orchard.Localization;
public Localizer T { get; set; }
var propertiesToInclude = new Dictionary<string, string>
{
{"ApproveDate", T("ApproveDate").Text}
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is not an excel file. I think the content type is incorrect, it should be:
1) Another content type that you could try is "application/csv"
2) If more help needed please provide what version of.NET and .NETMVC you re using and how your public method calls your code snippet
_workContextAccessor.GetContext().HttpContext.Response.ContentType = "text/csv";
Note:1) Another content type that you could try is "application/csv"
2) If more help needed please provide what version of.NET and .NETMVC you re using and how your public method calls your code snippet
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi All,
Thank you for trying to help me!
Miguel Oz , I tried all the solution you provided. But nothing worked. The .net version I am using is 4.8.3761.0
The public method called is this.
Thank you all so much for your time!
Thank you for trying to help me!
Miguel Oz , I tried all the solution you provided. But nothing worked. The .net version I am using is 4.8.3761.0
The public method called is this.
public void ExportAsDelimitedFile<T>(string filename, IEnumerable<T> items) {
var builder = new StringBuilder();
foreach (var item in items) {
builder.AppendLine(item.ToString());
}
PushCsv(builder, filename);
}
Jonathan Dahan , Can you please tell me in my code above how I can add the encoding info(UTF-8 encoding)Thank you all so much for your time!
ASKER
I added this and it is working fine now!
_workContextAccessor.GetContext().HttpContext.Response.ContentEncoding = Encoding.GetEncoding("Windows-1252");
windows-1252 defined at Microsoft's site.
Here's a quote from DBpedia:
Here's a quote from DBpedia:
Windows-1252 or CP-1252 (code page 1252) is a single-byte character encoding of the Latin alphabet, used by default in the legacy components of Microsoft Windows for English and many European languages including Spanish, French, and German. Depending on the country, use can be much higher than the global average, e.g. for Germany (including ISO-8859-1) at 6.3%.
ASKER
This is the code that sends the data to CSV file.
Open in new window