Automatically printing Crystal Reports in ASP. NET

Source: Internet
Author: User

This server-based method is already ented in the Visual Studio help files. Open the help index, and enter printtoprinter in the "look for:" box. The syntax for this method is:

 Report.PrintToPrinter(<copies as int>, <collated as True/False>, <startpage as int>, <endpage as int>)

 

'Collated' in this context has nothing to do with database collation. some advanced printers (like copier/printers) will sort each document into its own shelf. not every printer supports this functionality, so check the printer Dialog before setting to true. to print the entire report, set startpage and endpage each to 0.

An example in use might look like

MyReport.PrintToPrinter(1,False,0,0)

 

One limitation of this method is that a printer name must be specified. you can set the default printer at design time in the report, and you can change the printer name at run time by setting the reportdocument. printoptions. printername property (the printoptions are also where you can assign page margins, portrait/landscape, etc .). keep in mind that this method prints from the server itself, not from the client machine. this means that any printer you wish to use must be accessible from the server. you cannot print to a client's desktop printer using this method unless that printer is shared on the network and mapped to the server.

If your lan has networked printers, you can make some guesses as to which printer to assign as the default in each report. for instance, if the accounting department has a departmental printer, that wocould be a good choice to use for the default in an accounting report. you can provide users the option to choose a networked printer by enumerating the printers mapped to the server and populating a drop-down list. the printersettings. installedprinters property returns a collection of installed printers, and can be bound to a dropdownlist as below.

DropDownList1.DataSource = System.Drawing.Printing.PrinterSettings.InstalledPrintersDropDownList1.DataBind()

 

Again, since this code is executing on the server, this will only enumerate the printers on the server mapped to the System user. if a printer does not appear in the drop-down list, you need to ensure that it is properly mapped to the System user (see below ).

All printers and. NET framework need to be mapped to the System user in order for this to work. this is not a trivial task to configure. printers can be mapped to the system account only by editing the registry, and since the Framework is mapped to the System user, you may need to reassign security permissions on files and folders. this process is outlined in the "printing web-based reports from the server" article in The. NET Help Files (look up "Crystal Reports, printing" in the vs Help Index to link to the articles .) and also in Reference 3 (at the end of this Article ). the process is a little too intricate to cover here (leave comments if help is needed, and I can amend the Article later ).

 

Comment: This Article is a bit too long. There are two modes for printing Crystal Reports: Server printing and client printing.

The above describes the methods and ideas for printing on the server, which are summarized as follows:

1. Printing method:

Mainly used: Report. printtoprinter (<copies as int>, <collated as true/false>, <startpage as int>, <endpage as int>)

For instance:

 

Crystaldecisions. crystalreports. Engine. reportdocument reportdoc = new reportdocument ();

/// <Summary>
/// Send it to the printer for Printing
/// </Summary>
/// <Param name = "printername"> printer </param>
Public void sendtoprinter (string printername, int startpage, int endpage)
{
Reportdoc. printoptions. printername = printername;
Reportdoc. printtoprinter (1, true, 1, endpage );
Javascript. Run ("window. Close ();");
}

2. How to obtain the printer:

Dropdownlist1.datasource = system. Drawing. Printing. printersettings. installedprinters
Dropdownlist1.databind ();

3. Questions about getting the printer idea:

The printer must be available on the current network and accessible to the system.

Related Article

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.