Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# code to output to TAB delimited file

Posted on 2008-10-25
3
Medium Priority
?
5,415 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 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

877 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