?
Solved

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

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

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.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

650 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