Click here to Skip to main content
11,701,948 members (63,787 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# C#4.0
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
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 3-Jul-12 21:47pm
Edited 3-Jul-12 22:27pm
(no name)502.3K
v2
Comments
Durgesh Chauhan at 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)

  Print Answers RSS
0 OriginalGriff 314
1 Sergey Alexandrovich Kryukov 310
2 Maciej Los 300
3 Mika Wendelius 119
4 So_Keeee 100
0 OriginalGriff 8,324
1 Sergey Alexandrovich Kryukov 7,422
2 CPallini 4,912
3 Maciej Los 4,196
4 Mika Wendelius 3,556


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 4 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100