RDLC 用ashx调用打印的例子
来源:互联网 发布:淘宝最近生意不好 编辑:程序博客网 时间:2024/05/21 06:54
研究了好久,开始是嵌入aspx页面中导出的打印的,觉得这样太浪费资源了所以现在嵌入到比较不耗资源的ashx文件中,其中涉及了RDLC的导出、嵌入aspx与ashx的不同点:
以下即ashx代码:
using System;
using System.Collections.Generic;
using System.Web;
using Microsoft.Reporting.WebForms;
using System.Data;
using System.Data.SqlClient;
namespace V3WEB.ashx.car
{
/// <summary>
/// Tra_Docnum_CostCount_Rpt 的摘要说明
/// </summary>
public class Tra_Docnum_CostCount_Rpt : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
ExportPDF(context);
}
private DataTable LoadData(HttpContext context)
{
DataTable dt = null;
string d1 = "2012-01-01"; //Request["d1"].ToString();
string d2 = "2012-01-01"; // Request["d2"].ToString();
string dept = ""; // Request["dept"].ToString();
string carno = ""; // Request["carno"].ToString();
dt = BLL.Car.Factory.getTra_DocnumBLL().Tra_Docnum_CostCount(d1, d2, dept, carno);
return dt;
}
public void ExportPDF(HttpContext context)
{
LocalReport localReport = new LocalReport();
localReport.ReportPath = HttpContext.Current.Server.MapPath("/Report/Car/Tra_Docnum_CostCount.rdlc");
DataTable dt = LoadData(context);
ReportDataSource reportDataSource = new ReportDataSource("DataSet1", dt); //必须指定“DataSet1”为数据集中名称
localReport.DataSources.Add(reportDataSource);
string reportType = "PDF"; //可以换成EXCEL,完成EXCEL导出功能。
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
//" <PageWidth>8.5in</PageWidth>" +
//" <PageHeight>11in</PageHeight>" +
//" <MarginTop>0.5in</MarginTop>" +
//" <MarginLeft>1in</MarginLeft>" +
//" <MarginRight>1in</MarginRight>" +
//" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
//生成PDF文件到renderedBytes中
renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension, //可以在此设置文件名
out streams,
out warnings);
context.Response.Buffer = true;
context.Response.Clear();
context.Response.ContentType = mimeType;
context.Response.BinaryWrite(renderedBytes);
context.Response.Flush();
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
- RDLC 用ashx调用打印的例子
- RDLC报表的直接打印
- RDLC打印
- Winform rdlc 报表的直接打印
- rdlc打印多出空白页的问题解决
- ashx获取处理数据的简单例子
- ashx文件调用Session变量的方法
- ashx页面中调用自定义的Profile
- rdlc报表连续打印
- RDLC 打印方式
- rdlc报表打印
- rdlc报表预览打印
- C# winform打印RDLC
- RDLC 报表打印
- 在用ajax调用时在xx.ashx后传递参数,根据传递的参数值的不同,调用xx.ashx中相应的方法
- 在不预览的情况下打印RDLC报表
- 采用本地RDLC报表进行一维条码的打印
- [转]在不预览的情况下打印RDLC报表
- php最全面试题
- 招商银行网上客服
- 邮件相关知识网站
- liunx命令大全 (学好liux的必用指令)
- Android虚拟机Dalvik
- RDLC 用ashx调用打印的例子
- Mysql 命令行查询用户权限host所有用户
- LINUX下GDB调试
- AIX 6.1 安装 oracle 10gR2之(一)----硬件准备
- asp.net日历
- 使用mutt+msmtp做linux邮件客户端
- 招商银行余额变动提醒
- NLog日志——将日志保存在文件中
- 常用的aix命令