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();
}
 }

沒有留言:

張貼留言

publish error allowDefinition='MachineToApplication'

一個老舊的aspx web form專案,調了一些功能建置成功,但進行部署時顯示以下錯誤。 在應用程式層級之外使用註冊為 allowDefinition='MachineToApplication' 的區段發生錯誤。錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為...