Use code to export reportviewer

Source: Internet
Author: User
Public Partial Class _ Default: system. Web. UI. Page
{

String m_currentreport;

Private VoidSaverptas (string s_rpttype)
{

Warning [] warnings;
String [] Streamids;
String Mimetype;
String Encoding;
String Extension;
// String deviceinfo;

Byte [] Bytes = Reportviewer1.serverreport. Render (
S_rpttype, Null , Out Mimetype, Out Encoding, Out Extension,
Out Streamids, Out Warnings );

/*
Filestream stream = file. openwrite (@ "C: \ Documents ents and Settings \ Michael. Shorten \ Local
Settings \ temp \ sample.pdf ");
Stream. Write (bytes, 0, bytes. Length );
Stream. Close ();
*/

Response. Buffer= True;
Response. Clear ();
Response. contenttype=Mimetype;
Response. addheader ("Content-Disposition","Attachment; filename = sample."+Extension );
Response. binarywrite (bytes );
Response. Flush ();

}

protected void page_load ( Object sender, eventargs e)
{

If(!(Request. querystring ["RPT"]= Null))
{
M_currentreport=Request. querystring ["RPT"]. Tostring ();
Showreport (m_currentreport );
}

}

Private VoidShowreport (StringSreportpath)
{

//Set processing mode

Reportviewer1.processingmode=Processingmode. Remote;

//Set Report Server and Path

Reportviewer1.serverreport. reportserverurl= NewUri (http://Localhost/reportserver );
Reportviewer1.serverreport. reportpath=Sreportpath;

}

Protected VoidBtnsaveexcel_click (ObjectSender, eventargs E)
{

Saverptas ("Excel");

}

Protected VoidBtnsave1__click (ObjectSender, eventargs E)
{

Saverptas ("PDF");

}

}

From: https://forums.microsoft.com/MSDN/ShowPost.aspx? Postid = 139828 & siteid = 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.