Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Exporting the Crystal Report XI R2 using C#

Posted on 2009-05-07
2
Medium Priority
?
587 Views
Last Modified: 2013-12-17
Hi,

I am creating a new program to generate and export the Crystal report as xls using C#. I have created a rpt file using CR binding to xsd.  The requirement is the rpt and the xsd should not be included in the solution. During the runtime, I am loading the rpt file and assigning hte dataset. But I am getting the error Logon Failed during the time of export
The Error is in the line ExportReport.Export.ObjRpt.Export

Please advise
public void Load()
        {
            string ConnectionDetails = GetConfigSetting("Connection");
             ReportDocument _CrystalReport;
            _CrystalReport = new ReportDocument();
 
            _CrystalReport.Load(@"C:\\Report1.rpt");
 
            SqlConnection Connection = new SqlConnection(ConnectionDetails);
            SqlCommand Command = new SqlCommand("GetDATA", Connection);
            Command.CommandType = CommandType.StoredProcedure;
 
	    SqlDataAdapter dsDA = new SqlDataAdapter(Command);
            DataSet dsReport = new DataSet();
            
            try
            {
                dsDA.Fill(dsReport);
                _CrystalReport.SetDataSource(dsReport);
                
            }
            catch (Exception Ex)
            {
                Console.WriteLine("Exception ocurred in LoadData \n {0}", Ex.Message.ToString());
            }
 
       
                    try
            {
            ExportReport rptExp = new ExportReport("xls", "C:", "test");
 
            rptExp.Report = _CrystalReport;
 
            string _exportedFile = rptExp.Export();
            Console.WriteLine("File [{0}] successfully exported", _exportedFile);
        }
        catch (Exception Ex)
        {
 
            Console.WriteLine("Exception ocurred in LoadData \n {0}", Ex.Message.ToString());
 
        }
 
	ExportReport.cs
	---------------
 
	 private void ConfigureExportToXls()
        {
            objExportOpt.ExportFormatType = ExportFormatType.Excel;
 
            ExcelFormatOptions objExcelOptions = new ExcelFormatOptions();
            objExcelOptions.ExcelTabHasColumnHeadings = true;
            objExcelOptions.ShowGridLines = true;
            objExcelOptions.ExcelUseConstantColumnWidth = false;
            objExportOpt.ExportFormatOptions = objExcelOptions;
            objdiskDest.DiskFileName = exportPath +  expfileName + ".xls"; ;
            objExportOpt.DestinationOptions = objdiskDest;
        }
	 public string Export()
        {
            //try
            {
                ExportSetup();
                ExportSelection();
                exportedfile = objdiskDest.DiskFileName.ToString();
                objRpt.Export();
                return exportedfile;
            }
 
        }
private void ExportSelection()
        {
            switch (expFormat)
            {
                case "rpt"://  ExportFormatType.CrystalReport
                    ConfigureExportToRpt();
                    break;
                case "rtf"://ExportFormatType.RichText
                    ConfigureExportToRtf();
                    break;
                case "wrd": //ExportFormatType.WordForWindows
                    ConfigureExportToDoc();
                    break;
                case "xls": //ExportFormatType.Excel:
                    ConfigureExportToXls();
                    break;
                case "pdf"://ExportFormatType.PortableDocFormat:
                    ConfigureExportToPdf();
                    break;
                case "html32"://ExportFormatType.HTML32:
                    ConfigureExportToHtml32();
                    break;
                case "html40"://ExportFormatType.HTML40:
                    ConfigureExportToHtml40();
                    break;
            }
        }
 
	  private void ExportSetup()
        {
 
            if (!System.IO.Directory.Exists(exportPath))
            {
                System.IO.Directory.CreateDirectory(exportPath);
            }
            objdiskDest = new DiskFileDestinationOptions();
            objExportOpt = objRpt.ExportOptions;
            objExportOpt.ExportDestinationType = ExportDestinationType.DiskFile;
            objExportOpt.FormatOptions = null;
        }

Open in new window

0
Comment
Question by:vonbalaji
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 101

Accepted Solution

by:
mlmcc earned 80 total points
ID: 24329581
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question