Hi Kid1981,
It's easy...First u create a Dataset and populate the dataset using a Stored Proc or any other sources and then base your report on this dataset...Then once the report is displayed in CRViewer , u can export it on the click of a print button using the code I mention below. This code exports to PDF...u can export it to any other format. Just go thru the code properly and u will understand what to do...
using CrystalDecisions.CrystalReports.Engine ;
using CrystalDecisions.Shared ;
try
{
string Fname;
bool lboolExists = false ;
ExportOptions crExportOptions = new ExportOptions();
// populating dataset and binding to report
dsCampSumm = PopulateDataSet();
// binding report again
//CampSumm is the reportname
oRptCampSumm = new CampSumm();
oRptCampSumm.SetDataSource(dsCampSumm);
//This section of code is needed to check for existence of the folder
//where the pdf file will be temporarily stored
//--------------------------------------------------------------------------
Scripting.FileSystemObject lObjFSO ;
lObjFSO = new Scripting.FileSystemObjectClass();
lboolExists = lObjFSO.FolderExists(Server.MapPath("../../SaleSourceTemplates/" + GetSessionAgencyId()));
// Check for the folder name equal to Agency_id if false create one
if (lboolExists == false)
{
lObjFSO.CreateFolder(Server.MapPath("../../SaleSourceTemplates/" + GetSessionAgencyId()));
}
//--------------------------------------------------------------------------
Fname = Server.MapPath("../../SaleSourceTemplates/" + GetSessionAgencyId() + "/") + Session.SessionID.ToString() + ".pdf";
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
CrDiskFileDestinationOptions.DiskFileName = Fname;
crExportOptions = oRptCampSumm.ExportOptions;
crExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
oRptCampSumm.Export();
// The following code writes the pdf file to the Clientâs browser.
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(Fname);
Response.Flush();
Response.Close();
//delete the exported file from disk
System.IO.File.Delete(Fname);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
private DsReport PopulateDataSet()
{
dsCampSumm = new DsReport();
try
{
gstrQuery="sp_CampSumm ";
if (Request.QueryString["CampId"]=="All") //CampId
gstrQuery=gstrQuery + BusinessRules.Reports.CAMPID + ",";
else
gstrQuery=gstrQuery + Request.QueryString["CampId"] + ",";
if (Request.QueryString["CampManagerId"]=="All") //CampManagerId
gstrQuery=gstrQuery + BusinessRules.Reports.MANAGERID + ",";
else
gstrQuery=gstrQuery + Request.QueryString["CampManagerId"] + ",";
if (Request.QueryString["StartDate"]!=null) //Start Date
gstrQuery=gstrQuery + "'" + Request.QueryString["StartDate"] + "'" + ",";
else
gstrQuery=gstrQuery + "''" + ",";
if (Request.QueryString["Status"]!=null) //Status
gstrQuery=gstrQuery + "'" + Request.QueryString["Status"] + "'" + ",";
else
gstrQuery=gstrQuery + "'" + BusinessRules.Reports.STATUSBOTH + "'" + ",";
if (Request.QueryString["Launch"]!=null) //Launched
gstrQuery=gstrQuery + "'" + Request.QueryString["Launch"] + "'" + ",";
else
gstrQuery=gstrQuery + "'" + BusinessRules.Reports.LAUNCHBOTH + "'" + ",";
gstrQuery=gstrQuery + GetSessionAgencyId() + ",";
gstrQuery=gstrQuery + GetSessionBranchId();
SqlConnection myconnection = new SqlConnection() ;
//myconnection.ConnectionString = "server=DEBARSHI;database=SaleSource;uid=SSAdmin;p wd=admin";
myconnection.ConnectionString = "Server=" + GetDatabaseServerName() + ";" +
"Database=" + GetDatabaseName() + ";" +
"uid=" + GetSQLUserId() + ";" +
"pwd=" + GetSQLPassword();
myconnection.Open();
SqlCommand mycommand = new SqlCommand();
mycommand.Connection = myconnection;
mycommand.CommandText = gstrQuery;
mycommand.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = mycommand;
da.Fill(dsCampSumm, "CampaignSummary");
}
catch(Exception pEx)
{
throw new SaleSourceException(pEx.Message + " " + pEx.StackTrace,pEx,GetSessionUserId());
}
return dsCampSumm;
}
Quote:
quote:Originally posted by kid1981
Yes, I have already done it/
But I don't known export report to File from page N to page M/
Do you help me/
"Export to File or Export to Plug-in msword" from page to page/
Thanks
|
cheers,
debsoft