0 Replies - 337 Views - Last Post: 31 January 2012 - 10:01 PM Rate Topic: -----

Topic Sponsor:

#1 kirabitoy101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-November 11

Export single record to word document in Crystal Report VS2008

Posted 31 January 2012 - 10:01 PM

I have the code below where it exports all the record into a single word file.
Well, I'm having a problem in exporting a single record to word document. In other words, I want the chosen record to be exported in a single word document every time the user clicks the cmdExportandSend button.


private ReportDocument hierarchicalGroupingReport;
        private string exportPath;
        private DiskFileDestinationOptions diskFileDestinationOptions;
        private ExportOptions exportOptions;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            hierarchicalGroupingReport = new ReportDocument();
            hierarchicalGroupingReport.Load(Server.MapPath("CrystalReport1.rpt"));
            hierarchicalGroupingReport.SetDatabaseLogon
                ("admin", "admin", "localhost", "");
            CrystalReportViewer1.ReportSource = hierarchicalGroupingReport;
         }

        private void ExportSetup()
        {
            exportPath = "C:\\Exported\\";

            if (!System.IO.Directory.Exists(exportPath))
            {
                System.IO.Directory.CreateDirectory(exportPath);
            }

            diskFileDestinationOptions = new DiskFileDestinationOptions();
            exportOptions = hierarchicalGroupingReport.ExportOptions;
            exportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
            exportOptions.FormatOptions = null;
        }


        private void ExportCompletion()
        {
            try
            {
                hierarchicalGroupingReport.Export();
                lblWarning.Text = "SUCCESS";
            }
            catch (Exception ex)
            {
                lblWarning.Text = "FAILURE" + ex.Message;
            }

            lblWarning.Visible = true;
        }


        private void ConfigureExportToDoc()
        {
            exportOptions.ExportFormatType = ExportFormatType.WordForWindows;
            diskFileDestinationOptions.DiskFileName = exportPath + "Word.doc";
            exportOptions.DestinationOptions = diskFileDestinationOptions;
        }

        protected void cmdExportandSend_Click(object sender, EventArgs e)
        {
            ExportSetup();
            ConfigureExportToDoc();
            //ExportSelection();
            ExportCompletion();
        }



Best Regards,
Ernie

Is This A Good Question/Topic? 0
  • +

Page 1 of 1