Export format of Crystal Report

Source: Internet
Author: User

Using system;
Using system. collections;
Using system. componentmodel;
Using system. configuration;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using crystaldecisions. shared;
Using crystaldecisions. crystalreports. engine;
Using system. IO;
Using ghy. Funds. fundsclasslibrary;
Using system. Data. sqlclient;

Namespace webapptest
{
/// <Summary>
/// Summary of webform1.
/// </Summary>
Public class webform1: system. Web. UI. Page
{

Protected system. Web. UI. webcontrols. dropdownlist dropdownlist1;
Protected crystaldecisions. Web. crystalreportviewer crystalreportviewer1;
Protected system. Web. UI. webcontrols. Button btn_export;
ReportDocument reportdoc = new reportdocument ();

// page loading
// sqlconnection myconn = new sqlconnection (configurationsettings. appsettings ["connectstring"]);
// sqlconnection myconn1 = new sqlconnection (configurationsettings. appsettings ["connectstring"]);
// reads the web. the database connection string in the config configuration file and connects to the specified database
private void page_load (Object sender, system. eventargs e)
{< br> // put user code to initialize the page here
If (! Page. ispostback)
{< br> // bind during testing
reportdatabind ();
}< br>
}

# Region web form designer generated code
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}

/// <Summary>
/// Required method for designer support-do not modify
/// The contents of this method with the code editor.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );

}
# Endregion

// Bind the data source
Private void reportdatabind ()
{
Sqlconnection myconn = new sqlconnection ("Server = 10.100.0.8; database = eprocessdb; uid = sa; Pwd = admin @ SA ");
String SQL = "select distinct, distinct, funds_rpt_hq.inoth, funds_rpt_hq.payhq, distinct from funds_rpt_hq where limit = '2017-05-09 '";
Myconn. open ();
Sqldataadapter mycomm = new sqldataadapter (SQL, myconn );
Dataset dset1 = new dataset ();
Mycomm. Fill (dset1, "funds_rpt_hq ");
Myconn. Close ();
String ls_rptpathname;
Ls_rptpathname = server. mappath (".") + "\ funds_rpt_hq.rpt ";
Reportdoc. Load (ls_rptpathname );
Reportdoc. setdatasource (dset1 );
Crystalreportviewer1.reportsource = reportdoc;


}

Private void btn_export_click (Object sender, system. eventargs E)
{// Content type

Reportdatabind ();

String contenttype = "";
String ls_filetype;
Ls_filetype = dropdownlist1.selectedvalue;
String myfilename = "exportformat ";
// String myfilename = request. mappath (".") + "file: // reportexportfile //" + session. sessionid + "." + ls_filetype;

Diskfiledestinationoptions opts = new diskfiledestinationoptions ();
Opts. diskfilename = myfilename;
Diskfiledestinationoptions myoptions = new diskfiledestinationoptions ();
Myoptions. diskfilename = myfilename;
Reportdoc. exportoptions. exportdestinationtype = exportdestinationtype. diskfile;
Crystaldecisions. Shared. exportoptions myexportoptions = reportdoc. exportoptions;
Myexportoptions. exportformattype = exportformattype. portabledocformat;

Opts. diskfilename = "C: \ filename.pdf ";
Reportdoc. exportoptions. destinationoptions = opts;
Reportdoc. Export ();

// Switch (dropdownlist1.selecteditem. value)
//{
// Case "pdf ":
// Contenttype = "application/pdf ";
// Myexportoptions. exportformattype = crystaldecisions. Shared. exportformattype. portabledocformat;
// Break;
//
// Case "Doc ":
// Response. contenttype = "application/MS-excel ";
// Myexportoptions. exportformattype = crystaldecisions. Shared. exportformattype. wordforwindows;
// Break;
//
// Case "Excel ":
// Contenttype = "application/vnd. MS-excel ";
// This. enableviewstate = false;
// Myexportoptions. exportformattype = crystaldecisions. Shared. exportformattype. Excel;
// Break;
//}
//
// Crystalreportviewer1.export ();
// Response. clearcontent ();
// Response. clearheaders ();
// Response. contenttype = contenttype;
// Response. writefile (myfilename );
// Response. Flush ();
// Response. Close ();
// System. Io. file. Delete (myfilename );

}

}
}

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.