savefiledialog

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

i have a form with a multiline textbox in it. it also has a savefiledialog.
how do i save the text in the textbox?

can anyone help me?

i'd be grateful if you could!
 
In the simplest form... you would do a ShowDialog() on your SaveFileDialog,
make sure that the DialogResult was one you want to save on... then do
something along the lines of...

StreamWriter sw = new StreamWriter(YourSaveFileDialog.FileName);
sw.Write (YourTextBox.Text);
sw.Close();

As you see, we create a new StreamWriter to write to the file location
specified by the SaveFileDialog, directly write the text out with the Write()
method, and close the file.

Brendan
 
hi there,

the StreamWriter is a missing reference. what is it anyway? is one of those
classes that come with every c# compiler?
 
string fileContents = _textbox.Text;
string filepath = "MyFilenameAndPath.Txt";

using (TextWriter writer = File.CreateText(filepath))
{
writer.Write(fileContents);
writer.Close();
}

Hope this helps...

Frisky
 
type using System.IO; at the top of the source file.
StreamWriter class is in System.IO namespace.
 
TextWriter, like StreamWriter and most other file IO classes can all be found
in System.IO.

Brendan
 
hi,

for the 100th time you have helped me and i thank you for the 100th time

you're a true friend!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top