我在我的客户端应用程序中添加了一个打开文件对话框,以便用户可以选择他们想要发送到 Web 服务的特定文件。
但是文件会在文件被选中时发送,而我希望有一个辅助提示,例如“发送 - ‘文件名’按钮是。按钮号。”在他们选择文件后弹出。
万一用户选择了错误的文件,他们将有机会看到他们选择了哪个文件。
到目前为止我有以下代码-
private void button1_Click(object sender, EventArgs e)
{
//Read txt File
openFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader myReader = new StreamReader(openFileDialog1.FileName);
myReader.Close();
string csv = File.ReadAllText(openFileDialog1.FileName);
我需要在他们选择文件后出现提示,但不确定如何执行此操作,因此非常感谢任何输入。
最佳答案
您需要在第一个对话框之后手动添加第二个检查:
private void button1_Click(object sender, EventArgs e)
{
//Read txt File
openFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (MessageBox.Show("Message", "Title",MessageBoxButtons.YesNo)==DialogResult.Yes)
{
StreamReader myReader = new StreamReader(openFileDialog1.FileName);
myReader.Close();
string csv = File.ReadAllText(openFileDialog1.FileName);
等等等等
关于 MessageBox.Show 的信息.您可以从此处获取有关可能的结果/选项的信息。
您可以通过使消息类似于以下内容来确保用户看到要上传的文件:
"Are you sure you want to upload " + openFileDialog1.FileName;
关于c# - 在用户选择文件后添加提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5894761/