provide-free-support Ujjwal's Blog: November 2014

Friday, November 21, 2014

Encoding issue when exporting linq data to CSV C#

Hi,

I had been generating export in csv format from C# Code.

I faced an issue where CSV content heading had some Currency symbols and those were perfectly getting displayed in CSV but when you open those in excel, it shows some corrupted symbols.

i managed to resolve it using below sequence of development tasks.

My Earlier Code

  byte[] Bytes = GetFileDataBytes(filename);
 return File(Bytes , "text/csv", "report-" + DateTime.Now.ToString("yyyy-MMM-dd") + ".csv");

My New Code

  byte[] Bytes = GetFileDataBytes(filename);
 var result = Encoding.UTF8.GetPreamble().Concat(Bytes).ToArray();
 return File(result , "text/csv", "report-" + DateTime.Now.ToString("yyyy-MMM-dd") + ".csv");

Using Above code, i managed to open csv in excel with all special characters in it. :)

Thanks,
Ujjwal
best-it-exam-    | for-our-work-    | hottst-on-sale-    | it-sale-    | tast-dumps-us-    | test-king-number-    | pass-do-it-    | just-do-it-    | pass-with-us-    | passresults-everything-    | passtutor-our-dumps-    | realtests-us-exam-    | latest-update-source-for-    | cbtnuggets-sale-exam    | experts-revised-exam    | certguide-sale-exam    | test4-sale-exam    | get-well-prepared-    | certkiller-sale-exam    | buy-discount-dumps    | how-to-get-prepared-for-the    | in-an-easy-way    | brain-dumps-sale    | with-pass-exam-guarantee    | accurate-study-material    | at-first-try    | 100%-successful-rate    | get-certification-easily    | material-provider-exam    | real-exam-practice    | with-pass-score-guarantee    | certification-material-provider    | for-certification-professionals    | get-your-certification-successfully    | 100%-Pass-Rate    | in-pdf-file    | practice-exam-for    | it-study-guides    | study-material-sku    | study-guide-pdf    | prep-guide-demo    | certification-material-id    | actual-tests-demo    | brain-demos-test    | best-pdf-download    | our-certification-material    | best-practice-test    | leading-provider-on    | this-course-is-about    | the-most-reliable    | high-pass-rate-of    | high-pass-rate-demo    | recenty-updated-key    | only-for-students-free-download    | courseware-plus-kit-for    | accurate-answers-of    | the-most-reliable-id    | provide-training-for    | welcome-to-buy    | material-for-success-pass    | provide-free-support    | best-book-for-pass    | accuracy-of-the-answers    | pass-guarantee-id    | pass-exam-key    | pass-sku-id    | study-for-exid    | pdf-sku-exid    | sku-pdf-id    | pdf-demo-key    | exam-demo-ske    | pass-it-dump    |
http://inn-on-the-hill.com/    | http://inn-on-the-hill.com/    |