Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# code to output to TAB delimited file

Posted on 2008-10-25
3
Medium Priority
?
5,414 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
[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
  • 2
3 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 22802044
\\t helps?
0
 
LVL 13

Accepted Solution

by:
TechTiger007 earned 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

715 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