Hi, I need your help with that saveFile code that seams to compile but hit with an exception:
private
void saveAsToolStripMenuItem_Click(object sender, EventArgs e){
SaveFileDialog saveFileDialog1 = new SaveFileDialog();saveFileDialog1.Filter =
"Text files (*.txt)|*.txt|All files (*.*)|*.*|RTF Files (*.rtf)|*.rtf";saveFileDialog1.FilterIndex = 3;
saveFileDialog1.RestoreDirectory =
true; if (saveFileDialog1.ShowDialog(this) == DialogResult.OK){
childForm childForm = new childForm(); String filename = saveFileDialog1.FileName; using (StreamWriter writer = new StreamWriter(filename)){
childForm.MdiParent =
this;childForm.richTextBox1.SaveFile(saveFileDialog1.FileName);
}
}
}

saveFileDialog
AnnabelP
Could you please answer a few questions that are in referenced in the comments (//) below.
Look at the code I provided below (SDK Code) from the RichTextBox.SaveFile Method (String) entry in help. In this it is assumed that the RichTextBox is on the current form which it seems is not the case in your example. Also note that the sample does not require you to have a StreamWriter.
The code fragement you provided leaves a lot to guess so I am not sure if I am answering your question completely so feel free to follow up.
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*|RTF Files (*.rtf)|*.rtf";
saveFileDialog1.FilterIndex = 3;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
{
//reference question 1
childForm childForm = new childForm();
String filename = saveFileDialog1.FileName;
using (StreamWriter writer = new StreamWriter(filename))
{
childForm.MdiParent = this;
//reference question 2 and 3
childForm.richTextBox1.SaveFile(saveFileDialog1.FileName);
}
}
}
SDK Code
public void SaveMyFile()
{
// Create a SaveFileDialog to request a path and file name to save to.
SaveFileDialog saveFile1 = new SaveFileDialog();
// Initialize the SaveFileDialog to specify the RTF extention for the file.
saveFile1.DefaultExt = "*.rtf";
saveFile1.Filter = "RTF Files|*.rtf";
// Determine whether 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.
richTextBox1.SaveFile(saveFile1.FileName);
}
}
Robert Reister
Tim Wong
Hi I am sorry for the mass. let me explain. I have MDI Form and ChildForm with richTextBox. That code is located on the mdi form. and the exception is that the file being saved is used by another process, but it is not. it didn't save anything anyway.
thnks jbattat
52179apb
Hi, Just question I am using the express C#. Since it's free it have less features then the regular VS 2005 Because the menu strip on the childForm did not merge with the menu strip on the mdi form, rather they one below the other.
jbattat
rivast_2001
SHakeelGhauri77
jcnewbie