我嘗試打開一個文本文檔,然後收到消息: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?因爲如果沒有,那麼你將無法加載它 –