2012年3月29日 星期四

Render RDLC on the fly

background將RDLC匯出成excel或pdf或word (vs2011)

public void renderRDL(string type, String rpath ,params ReportDataSource[] rds)
{
ReportViewer rv = new ReportViewer();
rv.LocalReport.ReportPath = rdlPath;
foreach (ReportDataSource rs in rds)
{
         rv.LocalReport.DataSources.Add(rs);
}
rv.ID = "myrpt";
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo = "";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = rv.LocalReport.Render(type, deviceInfo,out mimeType, out encoding, out fileNameExtension, out streams, out warnings); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = mimeType; HttpContext.Current.Response.HeaderEncoding = System.Text.Encoding.GetEncoding("big5"); //中文檔名時加此不會變亂碼HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=我的表." + fileNameExtension); HttpContext.Current.Response.BinaryWrite(renderedBytes); HttpContext.Current.Response.End();
}
 }

沒有留言:

張貼留言

IIS 網站無法下載中文檔名檔案因為取消高位元字元

 網址+中文檔案名稱方式下載檔案顯示 404 - 找不到檔案或目錄。 但英數字檔案名稱則可下載。 因為設定GCB IIS,其中1項 將高位元字元預設取消勾選了。 27 TWGCB-04-014-0028 要求篩選與其他限制模組 允許高位元字元 這項原則設定決定查詢...