添加用户选择文件后的提示

发布于 2024-11-05 05:22:45 字数 723 浏览 5 评论 0原文

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

我需要在他们选择文件后出现提示,但不知道如何执行此操作,因此任何输入将不胜感激。

I have added an open file dialog box to my client application so that the used can select a specific file they want to send to the web service.

However the file gets sent the moment the file has been selected, whereas I would like to have a secondary prompt e.g. "Send - 'file name' Button Yes. Button No." to pop up after they have selected the file.

This would be incase the user selected the wrong file they would have a chance to see which one they selected.

So far I have the following code -

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);

I need the prompt to come up after they have selected the file but not sure how to do this so any input would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

二手情话 2024-11-12 05:22:45

您需要在第一个对话框后手动添加第二个检查:

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;

you need to add the second check manually after the first dialog:

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);

etc etc

Information on MessageBox.Show. You can get information on the possible results/options from here.

You could ensure that the user sees the file to be uploaded by making the message something like:

"Are you sure you want to upload " + openFileDialog1.FileName;
幻梦 2024-11-12 05:22:45

MessageBox.Show(...) 是您正在寻找的方法。

MessageBox.Show(...) is the method you're looking for.

如若梦似彩虹 2024-11-12 05:22:45

您可以使用消息框:

 if (MessageBox.Show(string.Format("Upload {0}, are you sure?", openFileDialog1.FileName), "Please Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
 {
     // ...
 }

You can use a message box:

 if (MessageBox.Show(string.Format("Upload {0}, are you sure?", openFileDialog1.FileName), "Please Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
 {
     // ...
 }
叹倦 2024-11-12 05:22:45

修改后的代码示例。

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
     DialogResult dr = MessageBox.Show(message, caption, MessageBoxButtons.YesNo);

     if(dr == DialogResult.Yes )
        StreamReader myReader = new StreamReader(openFileDialog1.FileName);
        // more code
     else
        // do something else

A sample of the code modified.

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
     DialogResult dr = MessageBox.Show(message, caption, MessageBoxButtons.YesNo);

     if(dr == DialogResult.Yes )
        StreamReader myReader = new StreamReader(openFileDialog1.FileName);
        // more code
     else
        // do something else
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文