Sunteți pe pagina 1din 9

Export the Crystal Reports(PDF format) to our given Folder location.

To Do This:
We have to do three things

1. Creating Crystalreport1.rpt file


2. Creating Crystalreport1.aspx file

In the Process of Creating Crystalreport.rpt,These are the screens


we seen:

After this,

After this,
After this,
When we click a make new connection this following screen we will
seen.

Click on Next button,


After entering the details and Click on next button,

Click on finish.

Then send the Selected Data table to right side of the page by using
arrow buttons, which are located in the middle of the page as shown
in the below screen.
After selecting Data table, send the Data table rows to right
Side of the page as same as sending the Data table by using arrow
buttons.(see the below screen).
Click on Next then,

Click on Finish.

Now, We can see the Data table rows in the Field Explorer window
-->Database fields.
Drag and drop the Rows on the Sections3(Details) Part.
(see the below screen).
Now Create the the Crystalreport.aspx file.

In the Design page between the the div tags Drag and drop the
CrystalReportViewer tag. (ToolBox->CrystalReports-> CrystalReportViewer).
And add these namespaces

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Configuration;

And in the body of the page load Event paste the following code.

DateTime fulldate = DateTime.Now;

//Creating the the string variables and load the variables with
values of dates in our required way.

string uploaddt = fulldate.ToString("dd-MM-yyyy-hh.mm.ss");


string uploadmonth = fulldate.ToString("MMMyyyy");
string uploadyear = fulldate.ToString("yyyy");
string Fileext = null;

//getAppUploadPath() is the function used to get the Folder


location which is stored in web.config file.
object ab = getAppUploadPath();
string apppath = Convert.ToString(ab);

// Important part Line 38 to 47.


// If D:\jitendra\jit\DotnetUp\2010 not exists then it will
create.
//
if (!IsFolderexists(apppath, uploadyear))
{
createFolder(apppath, uploadyear);
createFolder(apppath + "\\" + uploadyear, uploadmonth);
}
// If D:\jitendra\jit\DotnetUp\2010\May2010 not exists then it
will create.
if (!ISFoldExists(apppath, uploadyear, uploadmonth))
{
createFolder(apppath, uploadyear);
createFolder(apppath + "\\" + uploadyear, uploadmonth);
}
string pd = "PDFFileCreatedOn_";

string bb = apppath + "\\" + uploadyear + "\\" + uploadmonth +


"\\" + pd + uploaddt + ".pdf";

ReportDocument cryrep = new ReportDocument();


cryrep.Load(Request.PhysicalApplicationPath +
"Crystalreport1.rpt");
cryrep.SetDatabaseLogon("sa", "sa");
CrystalReportViewer1.ReportSource = cryrep;
ExportOptions CrExportOptions = new ExportOptions();

DiskFileDestinationOptions CrDiskFileDestinationOptions = new


DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new
PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = bb;
CrExportOptions = cryrep.ExportOptions;
CrExportOptions.ExportDestinationType =
ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType =
ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions =
CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
cryrep.Export();
}

public static bool IsFolderexists(string location, string


foldername)
{
return Directory.Exists(location + "\\" + foldername);
}
public static bool ISFoldExists(string location, string
foldername, string month)
{
return Directory.Exists(location + "\\" + foldername + "\\" +
month);
}
public static bool createFolder(string location, string
foldername)
{
Boolean funflag = true;
Directory.CreateDirectory(location + "\\" + foldername);
return funflag;
}
public object getAppUploadPath()
{
return ConfigurationManager.AppSettings["Location"];
}

And in the web.config file Place this below code.

<appSettings>
<add key="CrystalImageCleaner-AutoStart" value="true" />
<add key="CrystalImageCleaner-Sleep" value="60000" />
<add key="CrystalImageCleaner-Age" value="120000" />
<add key="Location" value="D:\jitendra\jit\DotnetUp" />
</appSettings>

End run the Crystalreport1.aspx file.

S-ar putea să vă placă și