C# output to file and colunms

This is a discussion on C# output to file and colunms within the C# Programming forums, part of the General Programming Boards category; Hello, I have a simple c# program that takes the user input in text box and then the contents are ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    52

    C# output to file and colunms

    Hello,

    I have a simple c# program that takes the user input in text box and then the contents are output to a file, very simple. The only problem I'm having is that I have about three columns and can't get the files to output in the format I want.

    So here is what it looks like:

    Colunm1 Colunm2 Colunm3
    Label desc usr input box

    Code:
    private void saveToolStripMenuItem_Click(object sender, EventArgs e)
            {
                string[] lines = { textBox1.Text, textBox3.Text, textBox7.Text };
                System.IO.File.WriteAllLines(@"C:\TestFolder\Writeline.txt", lines);
            }
    So the above code works ok, but it only outputs colunm1 for label. How do I format the code so that the other two colunms and rows are output and aligned?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    You're just going to have write the lines manually I guess. Open a TextWriter and do something like:
    Code:
    writer.WriteLine("{0}\t{1}\t{2}", textBox1.Text, textBox3.Text, textBox7.Text);
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-17-2011, 03:51 AM
  2. output file is a unicode file under certain circumstances
    By rivkyfried1 in forum C Programming
    Replies: 4
    Last Post: 10-25-2010, 09:16 AM
  3. Replies: 3
    Last Post: 10-20-2006, 07:59 PM
  4. Input-Output File--Can't create a file...
    By zaracattle in forum C++ Programming
    Replies: 10
    Last Post: 10-18-2006, 10:15 AM
  5. I am lost on how to read from file and output to file?
    By vicvic2477 in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2005, 10:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21