July 18, 2011

SSRS special character issue in Html/CSV download, UTF-8

Special character means other than ASCII it could be French/Spanish etc. Sometime while working simple mistake cause this special character issue, special character appears as "?" or some other character.

This happens when special characters are not treated specially, for special character we should use UTF-8 encoding rather then ASCII.
SQL Server Reporting service there are option of Html and csv (download).


byte[] result = null;
                string format = @"CSV";
                string devInfo = null;
                string encoding;
                string mimeType;
                string[] streamIDs = null;
                string historyID = null;
                Warning[] warnings = null;
                ParameterValue[] reportParameters = null;
                ReportData reportData = null;

1) line to be updated
devInfo =  @"True";
rather than following.....
                    //devInfo = @"ASCII";
2) reportData.ReportOutData = Encoding.UTF8.GetString(result);
rather than
reportData.ReportOutData = Encoding.ASCII.GetString(result);


3) //Save CSV if (its csv)

File.WriteAllText(file, header+Output, Encoding.UTF8);
//header because in devInfo we have set it to NoHeader, so manually we need to set  it.

it will sure resolve the issue

Comment if it resolve/not-resolve the issue

No comments: