为什么我的OpenFileDialog没有工作?
问题描述:
我尝试打开一个文本文档,然后收到消息:try-catch
中的无效文件格式。我使用Visual Studio 2015与Visual C#和Windows窗体应用程序。为什么我的OpenFileDialog没有工作?
这里我对开放的功能代码:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
try {
// Create an OpenFileDialog to request a file to open.
OpenFileDialog openFile1 = new OpenFileDialog();
// Initialize the OpenFileDialog to look for RTF files.
openFile1.Filter = "Text Files (*.txt)|*.txt| RTF Files (*.rtf)|*.rtf| All (*.*)|*.*";
// Determine whether the user selected a file from the OpenFileDialog.
if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
openFile1.FileName.Length > 0)
{
// Load the contents of the file into the RichTextBox.
TextBox.LoadFile(openFile1.FileName);
}
}
catch (Exception a)
{
MessageBox.Show(a.Message);
}
}//end open
我希望你能帮助我与友好的愿望sniffi。
什么是完整的文件路径和名称要载入? –
C:\ Users \ H179850 \ Documents \ Verschiedene Aufzeichnungen( sniffi
它是.txt还是.rtf?因为如果没有,那么你将无法加载它 –