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

Member Avatar for iamthwee

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.

not sure but i think

realm.WriteLine(Go + comboBox1.Text);

commented: Don't bump old threads -1

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.

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

Friends, have you ever noticed that the current thread is three years old? Please do not resurrect threads that are years old. By doing so you run the risk of confusing current posters and/or reopening old wounds.

Please read the rules before posting again - http://www.daniweb.com/forums/thread78223.html and rules.

Thread Closed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.