Click here to Skip to main content
15,919,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every body

i have a problem with reports
actually my application is accessing database from SQL and i'm getting reports on crystal report.

is there any way to Export reports in ascii text format on notepad.
please help me.

Here the code
C#
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

// Add this using directive. 
using System.Diagnostics;

namespace CrystalReportsTest
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Diagnostics.Process notePad;
        private CrystalDecisions.Windows.Forms.CrystalReportViewer CrystalReportViewer1;
        private System.Windows.Forms.Button cmdExportToNotePad;
        private System.ComponentModel.Container components = null;

        // These are the Win32 error code for file not found or access denied.
        const int ERROR_FILE_NOT_FOUND =2;
        const int ERROR_ACCESS_DENIED = 5;

        private void cmdExportReportNotePad_Click(object sender, System.EventArgs e)
        { 
            // Invoke the Exort report dialog. Be sure and save the text
            // report to the My Documents directory. That is where the
            // printing routine will look for it.
            this.CrystalReportViewer1.ExportReport();

            //Print exported ascii report in NotePad
            PrintDoc();
        }

        public void PrintDoc()
        { 
            Process notePad = new Process(); 
            try
            {
                // Get the path that stores user documents. [My Documents]
                string myDocumentsPath = 
                        Environment.GetFolderPath(Environment.SpecialFolde r.Personal);

                // The exported file to be printed is assigned here.
                notePad.StartInfo.FileName = myDocumentsPath + "\\TestNotePad.txt"; 
                notePad.StartInfo.Verb = "Print";
                notePad.StartInfo.CreateNoWindow = true;
                notePad.Start(); // Process opens NotePad and Prints exported text report.
            } 
            // Note that if your word processor generates exceptions
            // such as this, they are handled first.
            catch (Win32Exception e)
            {
                if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
                {
                    Console.WriteLine(e.Message + ". Check the path.");
                } 
                else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
                {
                    Console.WriteLine(e.Message + 
                            ". You do not have permission to print this file.");
                }
            }
        }

        private void CrystalReportViewer1_Load(object sender, System.EventArgs e)
        {
            // CrystalReportTest is the report to export to text
            CrystalReportViewer1.ReportSource = new CrystalReportTest();

            // Export tool bar button is removed prorammatically
            // so that user's must use the programmed button.
            CrystalReportViewer1.ShowExportButton = true;
        }
    }
}
Posted
Updated 3-Jul-12 22:27pm
v2
Comments
Durgesh Chauhan 7-Jul-12 12:37pm    
can anyone solved this code am getting error on this line
CrystalReportViewer1.ReportSource = new CrystalReportTest();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900