locked
Convert Crystel Report to Text File

    Question

  • How to convert  crystal report to Text file using C#.
    Wednesday, February 02, 2011 1:05 PM

Answers

All replies

  •  

     

    Hello Sir,

    I hope the following code snippet can help you with the converting crystal report to Text file using C#.

    protected void Form1_load(object sender, EventArgs e){

    try{

    CrystalReport reportWord = new CrystalReport();
    SqlConnection myConnection =new SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _

                                                 "Initial Catalog=pubs;");

    SqlCommand  MyCommand = new  SqlCommand("SELECT * FROM authors",myConnection );

    SqlDataAdapter  myDA =new SqlDataAdapter();

    DataSet myDS = new DataSet();

    myDA.SelectCommand = MyCommand;

    myDA.Fill(myDS);

    rpt.SetDataSource(myDS);

       CrystalReportViewer1.ReportSource = rpt;

    }catch{}

    }

    private void Button1_Click(System.Object sender, System.EventArgs e)
    {
    	//This Code is used to Convert to word document
    
    	CrystalReport reportWord = new CrystalReport();
    	// Report Name 
    
    	string strExportFile = "d:\\TestText.txt";
    
    	reportWord.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
    
    	reportWord.ExportOptions.ExportFormatType = ExportFormatType.WordForWindows;
    
    	DiskFileDestinationOptions objOptions = new DiskFileDestinationOptions();
    
    	objOptions.DiskFileName = strExportFile;
    
    	reportWord.ExportOptions.DestinationOptions = objOptions;
    
    	reportWord.SetDataSource(myDS);
    
    	reportWord.Export();
    
    	objOptions = null;
    
    	reportWord = null;
    
    }
    

     

             

    Thursday, February 03, 2011 6:31 AM
  • Hi Nijesh_online:

    welcome to the MSDN Forum.

    Here is a sample on the codeproject:

    Convert Query Result into *.CSV, *.TXT, *.XLS or Fill Into Crystal Report:
    http://www.codeproject.com/KB/database/Database_To_Text_File.aspx

    If you have any questions, please feel free to tell us.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Neddy Ren Thursday, February 10, 2011 8:13 AM
    Friday, February 04, 2011 2:38 AM