Solved

C# code to output to TAB delimited file

Posted on 2008-10-25
3
5,411 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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