- In Windows .NET application, you will get the popup dialog asking for providing XPS file path and name when printing the report to "Microsoft XPS Document Writer"
- In ASP.NET application, as business requirement, you need to print the reports to "Microsoft XPS Document Writer" at Server side. Is it possible to achieve this without user intervention (providing XPS file path and name)?
- Crystal Reports 2008
- Crystal Reports XI R2
- Crystal Report SDK
Use the below sample code:
Dim rpt As New ReportDocument
'CrystalReportViewer1.ReportSource = rpt
Dim printerSettings As New System.Drawing.Printing.PrinterSettings
Dim pageSettings As New System.Drawing.Printing.PageSettings
printerSettings.PrinterName = "Microsoft XPS Document Writer"
printerSettings.PrintFileName = "c:\folder\myrpt.xps"
printerSettings.PrintToFile = True
rpt.PrintToPrinter(printerSettings, pageSettings, False)
If you do not specify the folder path in PrintFileName property ( eg: printerSettings.PrintFileName = "myrpt.xps") , XPS file will be generated at C:\WINDOWS\system32\inetsrv folder by default. Thus, you may get "Access is Denied" error due to the lack of permission of writing the file to this folder. You can use either of following solutions to solve the issue:
- Specify the folder path in PrinterName property. Also ensure the default build-in Network Service Account associated with the application's default worker process has "write" permission for the folder.
- Have your ASP.NET run under local system account. Please refer to the solution section of SAP KBA 1216640 as to how to change the worker process from the default "Network Service" to "Local System"
xps, print, file, form , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To