17 Replies Latest reply: May 14, 2012 5:44 PM by Don Williams RSS

Export to Exchange Folder using Crystal 2008

Dave Leighton
Currently Being Moderated

I am attempting to upgrade a program to use Crystal 2008 (C#).  One of the functions that the old program had was 'Export to Exchange' folder.

 

I have attempted to call the Export function on the ReportDocument but I only ever get the 'Invalid export options.' exception.

 

The code I have currently looks like this:

 

ReportDocument doc = (ReportDocument)CrystalReportViewer1.ReportSource;

                        ExportFormatType eft = GetExportFormatType(_format);

                        ExchangeFolderDestinationOptions exchangeFolderDestinationOptions = ExportOptions.CreateExchangeFolderDestinationOptions();

                        ExportOptions exportOptions = new ExportOptions();

                        exchangeFolderDestinationOptions.DestinationType = ExchangeDestinationType.ExchangePostDocMessage;

                        exchangeFolderDestinationOptions.FolderPath = _exchangeFolder; // Should be an exchange folder...

                        exchangeFolderDestinationOptions.Profile = _exchangeProfile; // "MS Exchange Settings"; // "Outlook";

                        exportOptions.ExportDestinationOptions = exchangeFolderDestinationOptions;

                        exchangeFolderDestinationOptions.Password = "password";

 

                        exportOptions.ExportDestinationType = ExportDestinationType.ExchangeFolder;

                        exportOptions.ExportFormatType = eft;

                         

                        doc.Export(exportOptions);

 

This code is based on the code found here: http://msdn.microsoft.com/en-us/library/aa645695(v=vs.71).aspx

I have searched online and on this forum but I haven't seen a solution.  The export example provided on this site uses an older version of Crystal Reports.

 

Does anyone have a code example to do this that works?

 

Dave

  • Re: Export to Exchange Folder using Crystal 2008
    Ludek Uher
    Currently Being Moderated

    In exportOptions.ExportFormatType = eft;

     

    What is "eft:?

     

    Normally, I'd be looking for something like:

     

    exportOptions.ExportFormatType = ExportFormatType.Excel;

     

    I suspect "eft" defines some export type, but what?

     

    Another idea; Download the eval of CR 2011 and see if you can export to Exchange from the designer. An eval of CR 2011 can be downloaded from [here|http://www.sap.com/solutions/sapbusinessobjects/sme/freetrials/index.epx].

     

     

     

    Ludek

    Follow us on Twitter http://twitter.com/SAPCRNetSup

    Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

    • Re: Export to Exchange Folder using Crystal 2008
      Dave Leighton
      Currently Being Moderated

      Hi Ludek,

       

      eft is a variable for the enumeration.  The function looks up which type is required for the export.  It returns ExportFormatType.Excel or one of the other members.

       

      I have the full version ov Crystal Reports 2008 so I'll see if I can export to Exchange within the environment as you suggest.

       

      Dave

       

      Edited by: DaveLeighton on Feb 29, 2012 5:52 PM

    • Re: Export to Exchange Folder using Crystal 2008
      Dave Leighton
      Currently Being Moderated

      Hi Ludek,

       

      It seems to be possible to export to an Exchange Folder from within the Crystal Reports 2008 environment.  I say 'seems' because the file I tried to export does not find it's way into my drafts folder (although there are no errors reported).

       

      I do need to be able to do this programmatically.  I assume there must be a way to switch this export feature on with the viewer control.

       

      Dave

  • Re: Export to Exchange Folder using Crystal 2008
    Don Williams
    Currently Being Moderated

    Hi Dave,

     

    This works:

     

            /// bunch added for most types...
                CrystalDecisions.Shared.PdfRtfWordFormatOptions pdfOpts = CrystalDecisions.Shared.ExportOptions.CreatePdfRtfWordFormatOptions();
                CrystalDecisions.Shared.ExcelDataOnlyFormatOptions excelOptsDataOnly = CrystalDecisions.Shared.ExportOptions.CreateDataOnlyExcelFormatOptions();
                CrystalDecisions.Shared.ExcelFormatOptions excelOpts = CrystalDecisions.Shared.ExportOptions.CreateExcelFormatOptions();
                CrystalDecisions.Shared.MicrosoftMailDestinationOptions mailOpts = CrystalDecisions.Shared.ExportOptions.CreateMicrosoftMailDestinationOptions();
                CrystalDecisions.Shared.DiskFileDestinationOptions diskOpts = CrystalDecisions.Shared.ExportOptions.CreateDiskFileDestinationOptions();
                CrystalDecisions.Shared.ExportOptions exportOpts = new CrystalDecisions.Shared.ExportOptions();
                CrystalDecisions.Shared.PdfFormatOptions PDFExpOpts = new CrystalDecisions.Shared.PdfFormatOptions();
                CrystalDecisions.Shared.HTMLFormatOptions HTMLExpOpts = new CrystalDecisions.Shared.HTMLFormatOptions();
                CrystalDecisions.Shared.ExchangeFolderDestinationOptions ExchExpOpts = new ExchangeFolderDestinationOptions();
                CrystalDecisions.Shared.ExchangeDestinationType ExchExpType = new ExchangeDestinationType();
    
    // name could be DaveLeighton@YourCompany#Inbox
    // ALSO NOTE: the destination folder is delimted by a # and Not the @ as show in CR 2011 ( I'll be tracking this )
                ExchExpOpts.FolderPath = "YourDefaultFolder#Inbox"; // Should be an exchange folder...
                ExchExpOpts.Profile = "Your Default Outlook Profile"; //_exchangeProfile; // "MS Exchange Settings"; // "Outlook";
                ExchExpOpts.Password = "password";
    
                exportOpts.ExportFormatOptions = PDFExpOpts;
                exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.ExchangeFolder;
                exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                exportOpts.ExportDestinationOptions = ExchExpOpts;
                rpt.Export(exportOpts);
                MessageBox.Show("Mail to Exchange folder sent Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

     

    Thanks

    Don

     

    Set to be fixed in CR 2011 Designer SP 02.14 - ADAPT01620443

     

    Edited by: Don Williams on Feb 29, 2012 8:59 AM

     

    Edited by: Don Williams on Feb 29, 2012 9:42 AM

    • Re: Export to Exchange Folder using Crystal 2008
      Dave Leighton
      Currently Being Moderated

      This is still failing for me with the same error.

       

      Ideally, I would like to be able to enable the same export fucntionality in the viewer control that there is in the CR 2008 environment (it prompts for the folder and the profile etc).

       

      Failing that, I'd like to get it working programmatically.

       

      In your example, ExchExpType is unused.  Is this correct?

       

      Dave

       

      Edited by: DaveLeighton on Feb 29, 2012 6:15 PM

      • Re: Export to Exchange Folder using Crystal 2008
        Don Williams
        Currently Being Moderated

        Hi Dave,

         

        What is the error you are getting?

         

        And yes, ExchExpType is not used or needed.

         

        If you want to create the same UI as CR then you need to create your own UI and fill boxes then set it in code with the options I used in my code.

         

        Unfortunately the Viewer does not support Exchange Folder.

         

        I was testing this in CR for VS 2010 but the same code should work in VS 2008 and Cr 2008 but I get an exception error...

         

        I'll have to dig more and possibly track it...

         

        Don

        • Re: Export to Exchange Folder using Crystal 2008
          Don Williams
          Currently Being Moderated

          Hi Dave,

           

          You replied to Ludek indicating the output did not make in into your folder. Were you using CR 2008 or 2011?

           

          What Service Pack are you on in Cr 2008?

           

          Also note the format:

           

          ExchExpOpts.FolderPath = "YourDefaultFolder#Inbox"

           

          Don

          • Re: Export to Exchange Folder using Crystal 2008
            Dave Leighton
            Currently Being Moderated

            Hi Don,

             

            Thanks for your efforts on my behalf.

             

            I have Crystal Reports 2008 Version 12.3.0.601.

            The 'About' window does not mention any service packs.

             

            Yes, I used the format indicated for the ExchExpOpts.FolderPath value.

             

            Dave

             

            Edited by: DaveLeighton on Mar 1, 2012 9:47 AM

          • Re: Export to Exchange Folder using Crystal 2008
            Dave Leighton
            Currently Being Moderated

            I want the same behaviour as the File->Send To->Exchange Folder within the Crystal Reports environment.

            This was available in previous versions of the viewer control.

            • Re: Export to Exchange Folder using Crystal 2008
              Don Williams
              Currently Being Moderated

              You are on Service Pack 3

               

              I've tracked this now and set it for Fix Pack 5.1

               

              ADAPT01620974

               

              You can get the Patches from:

               

              Crystal Reports 2008 Reference

               

              Don

              • Re: Export to Exchange Folder using Crystal 2008
                Dave Leighton
                Currently Being Moderated

                Thanks Don.

                 

                You are a star of the first magnitude in the SAP technical firmament...

                 

                • Re: Export to Exchange Folder using Crystal 2008
                  Don Williams
                  Currently Being Moderated

                  Developer confirmed this was resolved in Service Pack 5:

                   

                  using System.Data;
                  using System.Drawing;
                  using System.Text;
                  using System.Windows.Forms;
                  using CrystalDecisions.CrystalReports.Engine;
                  using CrystalDecisions.Shared;
                  namespace WindowsApplication1
                  {
                      public partial class Form1 : Form
                      {
                          public Form1()
                          {
                              InitializeComponent();
                          }
                          private void button1_Click(object sender, EventArgs e)
                          {
                              CrystalDecisions.Shared.PdfRtfWordFormatOptions pdfOpts = CrystalDecisions.Shared.ExportOptions.CreatePdfRtfWordFormatOptions();
                              CrystalDecisions.Shared.ExcelDataOnlyFormatOptions excelOptsDataOnly = CrystalDecisions.Shared.ExportOptions.CreateDataOnlyExcelFormatOptions();
                              CrystalDecisions.Shared.ExcelFormatOptions excelOpts = CrystalDecisions.Shared.ExportOptions.CreateExcelFormatOptions();
                              CrystalDecisions.Shared.MicrosoftMailDestinationOptions mailOpts = CrystalDecisions.Shared.ExportOptions.CreateMicrosoftMailDestinationOptions();
                              CrystalDecisions.Shared.DiskFileDestinationOptions diskOpts = CrystalDecisions.Shared.ExportOptions.CreateDiskFileDestinationOptions();
                              CrystalDecisions.Shared.ExportOptions exportOpts = new CrystalDecisions.Shared.ExportOptions();
                              CrystalDecisions.Shared.PdfFormatOptions PDFExpOpts = new CrystalDecisions.Shared.PdfFormatOptions();
                              //CrystalDecisions.Shared.HTMLFormatOptions HTMLExpOpts = new CrystalDecisions.Shared.HTMLFormatOptions();
                              CrystalDecisions.Shared.HTMLFormatOptions HTMLExpOpts = CrystalDecisions.Shared.ExportOptions.CreateHTMLFormatOptions();
                              CrystalDecisions.Shared.ExchangeFolderDestinationOptions ExchExpOpts = new CrystalDecisions.Shared.ExchangeFolderDestinationOptions();
                              //CrystalDecisions.Shared.ExchangeDestinationType ExchExpType = new CrystalDecisions.Shared.ExchangeDestinationType();
                              ReportDocument rpt = new ReportDocument();
                              rpt.Load(@txtRPTPath.Text);
                              ////  Replace your address with mine and enter your Outlook password
                              ExchExpOpts.FolderPath = @txtFolderPath.Text;
                              ExchExpOpts.Profile = @txtProfile.Text;
                              ExchExpOpts.Password = @txtPassword.Text;
                              exportOpts.ExportFormatOptions = PDFExpOpts;
                              exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                              exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.ExchangeFolder;
                              exportOpts.ExportDestinationOptions = ExchExpOpts;
                              rpt.Export(exportOpts);
                              MessageBox.Show("Mail to Exchange folder sent Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                          }
                      }
                  }

                   

                  Don

Actions