[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

URGENT:  Print DataGrid results to a text file

Posted on 2004-10-12
5
Medium Priority
?
195 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

656 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