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
string title =
TabPage myTabPage = new TabPage(title);
int index = tabControl1.TabPages.IndexOf(myTabPage);

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

this.textBox.richTextBox1 = new

// Load the contents of the file into the RichTextBox.
textBox.richTextBox1.LoadFile(openFileDialog1.File Name,

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


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

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

// Determine if the user selected a file name from the
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,

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.