Basically what i'm trying to do is delete an old textfile in place of a new one with the different text that a person types in.

this is basically the code:

string Go = "go to";

System.IO.File.Delete("C:/text.txt");
            StreamWriter realm = new StreamWriter("C:/text.txt");
            realm.WriteLine(Go);
            realm.Write(comboBox1.Text);
            realm.Close();
            MessageBox.Show("Done!", "Finished");

So, when they type in the combo box, the text they typed in there should appear after "go to" But the problem is that it makes two lines instead of 1 line. like this

go to
combobox.text

How can i change the code to make it so that my string, and combobox1.text stay on the same line?

Any help would be appreciated.

Thanks
SiPex

If you just changing parts of a text file wouldn't you have to read the old one into memory change it then write over the file? Or something akin to that?

If you just changing parts of a text file wouldn't you have to read the old one into memory change it then write over the file? Or something akin to that?

I'm just deleting the first file, and putting this one in instead. Just want to make the words appear on 1 line instead of 2.

Basically what i'm trying to do is delete an old textfile in place of a new one with the different text that a person types in.

this is basically the code:

string Go = "go to";

System.IO.File.Delete("C:/text.txt");
            StreamWriter realm = new StreamWriter("C:/text.txt");
            realm.WriteLine(Go);
            realm.Write(comboBox1.Text);
            realm.Close();
            MessageBox.Show("Done!", "Finished");

So, when they type in the combo box, the text they typed in there should appear after "go to" But the problem is that it makes two lines instead of 1 line. like this

go to
combobox.text

How can i change the code to make it so that my string, and combobox1.text stay on the same line?

Any help would be appreciated.

Thanks
SiPex

You need to change

realm.WriteLine(Go);

to

realm.Write(Go);

because WriteLine automatically adds New line.

Edited 6 Years Ago by jbrock31: n/a

ok u deleted the old file so it wont write to it just remove delete and just keep realm.write(Go);

Use binary writer if you want to get more controll over what you write

This article has been dead for over six months. Start a new discussion instead.