Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在用户选择文件后添加提示_C#_Web Services_Openfiledialog - Fatal编程技术网

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

C# 在用户选择文件后添加提示,c#,web-services,openfiledialog,C#,Web Services,Openfiledialog,我在客户端应用程序中添加了一个“打开文件”对话框,以便用户可以选择要发送到web服务的特定文件 但是,文件会在选择文件时发送,而我希望在他们选择文件后弹出一个辅助提示,例如“发送-‘文件名’按钮是。按钮否” 如果用户选择了错误的文件,他们将有机会看到所选的文件 到目前为止,我有以下代码- private void button1_Click(object sender, EventArgs e) { //Read txt File openFileDia

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

我需要在他们选择文件后出现提示,但不确定如何执行此操作,因此任何输入都将非常感谢。

MessageBox.Show(…)是您要查找的方法。

MessageBox.Show(…)是您要查找的方法。

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

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

关于的信息。您可以从这里获得有关可能结果/选项的信息

您可以通过以下方式确保用户看到要上载的文件:

"Are you sure you want to upload " + 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);
等等

关于的信息。您可以从这里获得有关可能结果/选项的信息

您可以通过以下方式确保用户看到要上载的文件:

"Are you sure you want to upload " + openFileDialog1.FileName;

您可以使用消息框:

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

您可以使用消息框:

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

修改的代码示例

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

修改的代码示例

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

它应该是Show()方法中标题前的第一条消息!它应该是Show()方法中标题前的第一条消息!