Solved

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

Posted on 2012-04-11
3
295 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
ID: 37834593
0
 

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 500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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