Solved

URGENT:  Print DataGrid results to a text file

Posted on 2004-10-12
5
193 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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

690 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