在开发多文档界面窗口时,打开.doc或者.txt时出现一下问题:未处理的“System.ArgumentException”类型的异常出现在 system.windows.forms.dll 中。其他信息: 无效的文件格式.
但是经过程序自己保存的.doc或.txt格式的文件就能顺利打开。有谁知道原因是什么吗?。下面是打开按钮的代码:
//构造一个OpenFileDialog通用对话框
OpenFileDialog ofDlg=new OpenFileDialog();
//设置文件过滤类型
            ofDlg.Filter="Rich Text Format(*.doc)|*.doc|All files(*.*)|*.*";
//缺省为doc文件
ofDlg.FilterIndex=1;
//缺省后缀为doc
ofDlg.DefaultExt="doc";
//自动加入后缀
ofDlg.AddExtension=true;
            //恢复当前文件夹
ofDlg.RestoreDirectory=true;
//只允许单选
ofDlg.Multiselect=false;
//显示对话框
if(ofDlg.ShowDialog()==DialogResult.OK)
{
                //新建子窗体
MDIChild child=new MDIChild();
//设置子窗体的标题
child.Text=ofDlg.FileName;
//设置子窗体的多文档父窗口
child.MdiParent=this;
//读入文档
child.richTextBox1.LoadFile(ofDlg.FileName);
child.Show();
}