?
Solved

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

Posted on 2012-04-11
3
Medium Priority
?
312 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
[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 Comments
 

Author Comment

by:Sirdots
ID: 37834617
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 2000 total points
ID: 37834627
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

770 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