?
Solved

URGENT:  Print DataGrid results to a text file

Posted on 2004-10-12
5
Medium Priority
?
194 Views
Last Modified: 2010-04-15
Is there an easy way to export the contents of a data grid to a text file?

Even better to print the contents directly to the printer....but if I can just get the contents out to a file I can print the text file myself.

Tom
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
Hans Langer earned 2000 total points
ID: 12293573
Maybe That Help:

you can change sw.Write(","); with the separator char,


private void OnExportGridToCSV(object sender, System.EventArgs e)
{
      // Create the CSV file to which grid data will be exported.
      StreamWriter sw = new StreamWriter(Server.MapPath("~/GridData.txt"), false);
      // First we will write the headers.
      DataTable dt = m_dsProducts.Tables[0];
      int iColCount = dt.Columns.Count;
      for(int i = 0; i < iColCount; i++)
      {
            sw.Write(dt.Columns[i]);
            if (i < iColCount - 1)
            {
                  sw.Write(",");
            }
      }
      sw.Write(sw.NewLine);
      // Now write all the rows.
      foreach (DataRow dr in dt.Rows)
      {
            for (int i = 0; i < iColCount; i++)
            {
                  if (!Convert.IsDBNull(dr[i]))
                  {
                        sw.Write(dr[i].ToString());
                  }
                  if ( i < iColCount - 1)
                  {
                        sw.Write(",");
                  }
            }
            sw.Write(sw.NewLine);
      }
      sw.Close();
}

Source: http://www.netomatix.com/DataGridSeries.aspx
GL
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12293658
This exports the contents.

The points are yours.....but is there a way to (simply) print the exported file?
0
 
LVL 10

Expert Comment

by:Hans Langer
ID: 12293897
You can read the file, format it and print it..
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12299126
Do you have sample code?
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question