c# - 在用户选择文件后添加提示

标签 c# web-services openfiledialog

我在我的客户端应用程序中添加了一个打开文件对话框,以便用户可以选择他们想要发送到 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/

相关文章:

c# - 继承 Class1 并实现 Interface1,以防 Class1 已经实现 Interface1

c# - 喜欢在 Active Directory 中搜索

c# - 将图像加载到文件流

c# - 使用带有相对路径的 OpenFileDialog 作为 initialDirectory

c# - 绑定(bind) appsettings.json 中的字符串列表

c# - WPF 双向绑定(bind)不起作用

java - 如何为 JSP 和 EJB3 网站创建 API

java - 将两个 DAO 中的数据合并到一个 TO 中

java - 在 Web 服务和客户端之间共享 Java 类

c# - 是否可以在末尾添加选定的文件而不是使用带有多选的 OpenFileDialog 开始?