• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

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

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.
1 Solution
SirdotsAuthor Commented:
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.
public void Write(DataTable dt, string filePath)
            int i = 0;
            StreamWriter sw = null;
                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(","); //lets add comma after every column value

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


Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now