TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Direct PDF Download From RDLC Without Opening Reportviewer
Abhishek Chadha
Sep 15
2015
Code
11.8
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
protected
void
Page_Load(
object
sender, EventArgs e)
{
aid = Session[
"aid"
].ToString();
if
(!IsPostBack)
{
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath(
"~/BCReport.rdlc"
);
barcode dsCustomers = GetData(
"select bar_image,Barcode,bar_code from Master_Item where bar_Code=@ad"
);
ReportDataSource datasource =
new
ReportDataSource(
"DataSet1"
, dsCustomers.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
//ReportViewer1.LocalReport.Refresh();
//Code For Download Direct PDF
Warning[] warnings;
string
[] streamIds;
string
mimeType =
string
.Empty;
string
encoding =
string
.Empty;
string
extension =
string
.Empty;
byte
[] bytes = ReportViewer1.LocalReport.Render(
"PDF"
,
null
,
out
mimeType,
out
encoding,
out
extension,
out
streamIds,
out
warnings);
// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer =
true
;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader(
"content-disposition"
,
"attachment; filename= barcode.pdf"
);
Response.BinaryWrite(bytes);
// create the file
Response.Flush();
}
}
private
barcode GetData(
string
query)
{
SqlConnection con = (SqlConnection)(HttpContext.Current.Session[
"conn"
]);
SqlCommand cmd =
new
SqlCommand(query);
using
(SqlDataAdapter sda =
new
SqlDataAdapter())
{
cmd.Connection = con;
cmd.Parameters.AddWithValue(
"@ad"
, aid);
sda.SelectCommand = cmd;
using
(barcode dsCustomers =
new
barcode())
{
sda.Fill(dsCustomers,
"DataTable1"
);
return
dsCustomers;
}
}
}
barcode report
rdlc report