Solved

Removing the Header section(first line) when creating a text file

Posted on 2012-04-11
3
280 Views
Last Modified: 2012-04-11
The  attached code  is used to generate a text file. However when the text file is generated It shows the header (field names) which I dont want. How can I create this text file without showing the header.
File.txt
0
Comment
Question by:Sirdots
3 Comments
 
LVL 19

Expert Comment

by:Manoj Patil
Comment Utility
0
 

Author Comment

by:Sirdots
Comment Utility
Thanks techChallenger1. If you read my question very well, my problem is not creating the text file. I was able to create it successfully. My problem is getting rid of the column names that appear on the first line.
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
Comment Utility
public void Write(DataTable dt, string filePath)
        {
            int i = 0;
            StreamWriter sw = null;
            try
            {
                sw = new StreamWriter(filePath, false);
                foreach (DataRow row in dt.Rows)
                {
                    object[] array = row.ItemArray;
                    for (i = 0; i < array.Length - 1; i++)
                    {
                        sw.Write(array[i].ToString());
                        sw.Write(","); //lets add comma after every column value
                    }

                    sw.WriteLine(); //lets add new line after every row
                }
                sw.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid Operation : \n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now