Click here to Skip to main content
15,511,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use to an app where you click on a button (Car) it then takes you to a new window where all the models are listed 1. Honda 2.Toyota 3. Fiat 4.Ferrari. Then you should input on the Textbox the number of the car model you want to save. So if you choose 1. when it saves threw Stringbuilder, the text should come out simply Honda.

       StringBuilder _car  = new StringBuilder();

   public MainWindow()

    private void Car()
    private void button1_Click(object sender, RoutedEventArgs e)
       using (SaveFileDialog dlg = new SaveFileDialog())
           if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
               string fileName = dlg.FileName;

private void SaveToFile(string fileName)

       System.IO.TextWriter w = new System.IO.StreamWriter(fileName);

What I have tried:

This is as far as I got, problem is I dont know how to use the List and how just save the word, now if i input a number it saves all the models.
Updated 23-Nov-17 16:45pm

1 solution

System.Windows.Forms = WinForm, not WPF. Are you sure that this is WPF?

If it is WPF app, then have a read of this to answer your question: WPF Tutorial - The SaveFileDialog[^]

If it is a WinForm app, then have a read of this to answer your question: How to: Save Files Using the SaveFileDialog Component | Microsoft Docs[^]

With regards to the List and StringBuilder[^], Your ouput string has no seperators in the name, so parsing the data back in will be troublesome. It will look like:

You need to have a delimiter to separate them out:
var cars = new string[] { "Honda", "Toyota", "Fiat", "Ferrari" };

var outString1 = String.Join(", ", cars);

// or

var outString2 = String.Join(Environment.NewLine, cars);
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900