我是C#的新手。
我的问题是打开文件对话框中的strFileName是什么?
我目前有此代码:
string input = string.Empty;
OpenFileDialog open = new OpenFileDialog();
open.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.* ";
open.InitialDirectory = "C:";
if (open.ShowDialog() == DialogResult.OK)
strFileName = open.FileName;
if (strFileName == String.Empty)
return;
它在strFileName上显示错误。我找不到有关此代码中功能的解释。
如有任何帮助,我们将不胜感激,如果您之前曾提出此问题,我深表歉意。
最佳答案
不知道错误是什么,仅通过查看代码,您可能会在strFileName上收到编译错误,因为未声明该错误:
您可以将代码更改为此:
string input = string.Empty;
OpenFileDialog open = new OpenFileDialog();
open.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.* ";
open.InitialDirectory = "C:";
if (open.ShowDialog() == DialogResult.OK)
input = open.FileName;
if (input == String.Empty)
return;
或这个:
string strFileName = string.Empty;
OpenFileDialog open = new OpenFileDialog();
open.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.* ";
open.InitialDirectory = "C:";
if (open.ShowDialog() == DialogResult.OK)
strFileName = open.FileName;
if (strFileName == String.Empty)
return;
关于c# - 打开文件对话框中的strFileName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13203815/