471,326 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

Saving text from new richTextBox

Hi! I'm having trouble creating a save funktion. How can I save the
contens of a new richTextBox that is created from an "external" class
file? The open funktion looks like this:
public void openFile()
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "Select a Text File";

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new
StreamReader(openFileDialog1.FileName);
string title =
Path.GetFileName(openFileDialog1.FileName);
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);
int index = tabControl1.TabPages.IndexOf(myTabPage);

//Add the RichTextBox to the tabPage.
NumberedTextBox.NumberedTextBoxUC textBox = new
NumberedTextBox.NumberedTextBoxUC();

this.textBox.richTextBox1 = new
System.Windows.Forms.RichTextBox();

// Load the contents of the file into the RichTextBox.
textBox.richTextBox1.LoadFile(openFileDialog1.File Name,
RichTextBoxStreamType.PlainText);
this.tabControl1.TabPages[index].Controls.Add(textBox);

// Active tabPage is the new tabPage.
this.tabControl1.SelectedTab = myTabPage;

sr.Close();

So the file i want to save is the loaded contens of
textBox.richTextBox1. The save funktion i made(doesn't work) looks like
this:

private void saveFile()
{

// Create a SaveFileDialog to request a path and file name
to save to.
SaveFileDialog saveFile1 = new SaveFileDialog();

// Initialize the SaveFileDialog to specify the extension
for the file.
saveFile1.FileName = tabControl1.SelectedTab.Text;
saveFile1.DefaultExt = "*.pon";
saveFile1.Filter = "Point (*.pon)|*.pon|Luna
(*.lun)|*.lun";

// Determine if the user selected a file name from the
saveFileDialog.
if (saveFile1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK &&
saveFile1.FileName.Length > 0)
{
// Save the contents of the RichTextBox into the file.
this.boxen.richTextBox1.SaveFile(saveFile1.FileNam e,
RichTextBoxStreamType.PlainText);

Feb 7 '06 #1
0 2218

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David Johnston | last post: by
3 posts views Thread by kangoo | last post: by
2 posts views Thread by Martin Dew | last post: by
4 posts views Thread by JRB | last post: by
8 posts views Thread by AxOn | last post: by
3 posts views Thread by michael sorens | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.