This is a migrated thread and some comments may be shown as answers.

CSV dump as ANSI instead of UTF8

1 Answer 889 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Cruz
Top achievements
Rank 1
John Cruz asked on 15 Jun 2011, 10:56 PM
Is there a way to convert the CSV file returned by ExportToCSV to ANSI-based csv file instead of a UTF8-based csv file?

I tried wiring to the Grid Exporting event but thats not working because the encoding is hardwired to the response.binarywrite call which is called after the GridExporting event. Any ideas?

It would be awesome if telerik allows customization for the export encoding to ASCII, ANSI, or UTF8. Maybe a property to set the encoding.

protected void grdTransaction_GridExporting(object sender, GridExportingArgs e)
{
    byte[] byteArray = Encoding.UTF8.GetBytes( e.ExportOutput);
    byte[] asciiArray = Encoding.Convert(Encoding.UTF8, Encoding.Default, byteArray);
    e.ExportOutput = Encoding.ASCII.GetString(asciiArray);       
}

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 21 Jun 2011, 09:32 AM
Hello John,

Please try the following approach:
protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
{
    if (e.ExportType == ExportType.Csv)
    {
        Response.ClearHeaders();
        Response.ContentType = "application/csv";
        Response.AddHeader("Content-Type", "text/csv");
         ...
        Response.BinaryWrite(new ASCIIEncoding().GetBytes(e.ExportOutput));
        Response.End();
    }
}

Let me know whether this helps.

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
John Cruz
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or