3

此代码生成上面的错误,我试图做一些将文件发送到 ftp 服务器的方法

public void btnSend_Click(object sender, GridViewCommandEventArgs e)
{


    msgerror = SP.StrSPBUS_DocClient(Convert.ToInt32(e.CommandArgument.ToString()));

    if (msgerror.Equals("Sucess"))
    {
        String Files = SP.OUTSTR_NMDOCUMENT;
        String Address = SP.OUTSTR_FTPCAM;
        String User = SP.OUTSTR_FTPUSER;
        String Pass = SP.OUTSTR_FTPPASS;

        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(Address + "/" + Path.GetFileName(File));
        request.Method = WebRequestMethods.Ftp.UploadFile;
        request.Credentials = new NetworkCredential(User, Pass);
        request.UsePassive = true;
        request.UseBinary = true;
        request.KeepAlive = false;

        var stream = File.OpenRead(Files);
        byte[] buffer = new byte[stream.Length];
        stream.Read(buffer, 0, buffer.Length);
        stream.Close();

        var reqStream = request.GetRequestStream();
        reqStream.Write(buffer, 0, buffer.Length);
        reqStream.Close();
    }
    else
    {
        SP.StrImprimeMessage("Error!");
        return;
    }
}

和文件 .aspx 这是按钮的代码

<tr class="tabelinner">
            <td class="leftcell" valign="middle">

                    <asp:Button ID="btnSrend" runat="server" Text="Send" CssClass="ButtonLink" ValidationGroup="sending"  CommandArgument="Sending" onclick="btnSend_Click"     />
                <br />
            </td>              
        </tr>
4

2 回答 2

6

问题是GridViewCommandEventArgs应该只是EventArgs

public void btnSend_Click(object sender, EventArgs e)

编辑:

我看到在你的代码中你使用了命令参数,所以如果你想使用它,你应该看到这篇文章

基本上使用onCommand而不是onClick或将发送者转换为按钮来获取命令参数,例如:

var argument = ((Button)sender).CommandArgument;
于 2013-10-15T22:17:11.940 回答
3

按钮单击事件的正确签名是

public void btnSend_Click(object sender, EventArgs e)

但是此时您遇到了问题,因为传递的 EventArgs 实例不知道名为 的属性e.CommandArgument,因此您需要另一种方法来在此事件中使用该值。

于 2013-10-15T22:17:19.027 回答