Solved

C# code to output to TAB delimited file

Posted on 2008-10-25
3
5,409 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
ID: 22802044
\\t helps?
0
 
LVL 13

Accepted Solution

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

Expert Comment

by:TechTiger007
ID: 22802085
single back slash followed by tee (\t)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

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