Solved

C# code to output to TAB delimited file

Posted on 2008-10-25
3
5,404 Views
Last Modified: 2013-12-17
I have a function that outputs the data i want to a comma separated file, but how can i ajust this to output to a TAB separated file? i was thinking it would be just /t where the "," are.

But that didnt seem to work. An i missing something?

Just for your information, DataGrid is actually a dataGridView.
private void ExportGridToCsv(string file)

{

    StreamWriter writer = new StreamWriter(file);
 

    if (DataGrid.Rows.Count > 0)

    {

        foreach (DataGridViewColumn col in DataGrid.Columns)

        {

            if (col.Index == DataGrid.Columns.Count - 1)

            {

                writer.WriteLine(col.HeaderText);

            }

            else

            {

                writer.Write(string.Concat(col.HeaderText, ","));

            }

        }
 

        foreach (DataGridViewRow row in DataGrid.Rows)

        {

            

                foreach (DataGridViewCell cell in row.Cells)

                {

                    if (cell.OwningColumn.Index == DataGrid.Columns.Count - 1)

                    {

                        if (cell.Value != null)

                            writer.WriteLine(cell.Value.ToString());

                        else

                            writer.WriteLine("");

                    }

                    else

                    {

                        if (cell.Value != null)

                            writer.Write(string.Concat(cell.Value.ToString(), ","));

                        else

                            writer.Write(string.Concat("", ","));

                    }

                }

            

        }

    }
 

    writer.Close();

}

Open in new window

0
Comment
Question by:A_Kardas
  • 2
3 Comments
 
LVL 20

Expert Comment

by:informaniac
Comment Utility
\\t helps?
0
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 125 total points
Comment Utility
It is "\t" for tab character
0
 
LVL 13

Expert Comment

by:TechTiger007
Comment Utility
single back slash followed by tee (\t)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
c#.net application + check if already running 5 48
Problem to Popup 2 47
Total in textboxes 9 33
Problem to picture file 3 36
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

10 Experts available now in Live!

Get 1:1 Help Now