Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.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
SavefileDialog不支持';我的C#代码上没有显示_C#_Savefiledialog - Fatal编程技术网

SavefileDialog不支持';我的C#代码上没有显示

SavefileDialog不支持';我的C#代码上没有显示,c#,savefiledialog,C#,Savefiledialog,各位。我有一个C代码。在我的代码中,savefiledialog无法打开,我不知道为什么。请帮帮我 public void ReceiveTCP(int portN) { TcpListener Listener = null; try { Listener = new TcpListener(IPAddress.Any, portN); Listener.Start(); } catch (Exception ex)

各位。我有一个C代码。在我的代码中,savefiledialog无法打开,我不知道为什么。请帮帮我

public void ReceiveTCP(int portN)
{
    TcpListener Listener = null;
    try
    {
        Listener = new TcpListener(IPAddress.Any, portN);
        Listener.Start();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }

    byte[] RecData = new byte[BufferSize];
    int RecBytes;

    for (; ; )
    {
        TcpClient client = null;
        NetworkStream netstream = null;
        Status = string.Empty;
        try
        {                          
             string message = "Accept the Incoming File ";
             string caption = "Incoming Connection";
             MessageBoxButtons buttons = MessageBoxButtons.YesNo;
             DialogResult result;

             if (Listener.Pending())
             {
                  client = Listener.AcceptTcpClient();
                  netstream = client.GetStream();
                  Status = "Connected to a client\n";
                  result = MessageBox.Show(message, caption, buttons);

                  if (result == System.Windows.Forms.DialogResult.Yes)
                  {
                       string SaveFileName=string.Empty;
                       SaveFileDialog DialogSave = new SaveFileDialog();
                       DialogSave.Filter = "All files (*.*)|*.*";
                       DialogSave.RestoreDirectory = true;
                       DialogSave.Title = "Where do you want to save the file?";
                       DialogSave.InitialDirectory = @"C:/";
                       if (DialogSave.ShowDialog() == DialogResult.OK)
                            SaveFileName = DialogSave.FileName;
                       if (SaveFileName != string.Empty)
                       {
                           int totalrecbytes = 0;
                           FileStream Fs = new FileStream
            (SaveFileName, FileMode.OpenOrCreate, FileAccess.Write);
                           while ((RecBytes = netstream.Read
                (RecData, 0, RecData.Length)) > 0)
                           {
                                Fs.Write(RecData, 0, RecBytes);
                                totalrecbytes += RecBytes;
                           }
                           Fs.Close();
                       }
                       netstream.Close();
                       client.Close();
                  }
             }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            //netstream.Close();
        }
    }
}

您是否在“是/否”对话框中单击“是”按钮?这是一个控制台应用程序吗?是的,我单击“是”,但没有显示此代码用于窗口应用程序窗体,因此您单击“是”按钮,然后什么也没有发生?什么都没有?没有保存对话框?也不例外?什么都没有?您是否在“是/否”对话框中单击“是”按钮?这是一个控制台应用程序吗?是的,我单击“是”,但没有显示此代码是针对窗口应用程序窗体的,因此您单击“是”按钮,然后什么也没有发生?什么都没有?没有保存对话框?也不例外?没有什么?