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
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shiv Kumar Yadav
NA
269
25.7k
Error while Downloading RDLC Report automatically in MVC
Mar 31 2018 1:54 AM
Hi Everyone,
I am Getting an error While Downloading a RDLC Report in
MVC (Controller)
.
But Same Code is Working on
ASPX
Page
Error : Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: The specified operation is not valid.
at : byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
void
ReportDownLoad(
string
id)
{
scon =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"connection"
].ConnectionString);
ReportViewer ReportViewer1 =
new
ReportViewer();
ReportViewer1.ProcessingMode = ProcessingMode.Local;
//set path of the Local report
ReportViewer1.LocalReport.ReportPath = Server.MapPath(
"~/Report/SingleReport.rdlc"
);
DataSet ds =
new
DataSet();
SqlDataAdapter adapt =
new
SqlDataAdapter(
"SELECT * from table1 where id='"
+id+"'", scon);
adapt.Fill(ds,
"DataTable1"
);
scon.Close();
//Providing DataSource for the Report
ReportDataSource rds =
new
ReportDataSource(
"DataSet1"
, ds.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
//Add ReportDataSource
ReportViewer1.LocalReport.DataSources.Add(rds);
//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= ReferenceNo"
+ id +
".pdf"
);
Response.BinaryWrite(bytes);
// create the file
Response.Flush();
}
Note Same Code is Working in ASPX Page.
Please Help me.
Reply
Answers (
1
)
Robotic process automation position for dot net developer
How Can i Download and install MVC for VS 2015?