2012-02-24 297 views
-1

我正在編寫一個程序,在按鈕單擊事件中使用FTP訪問遠程文件數據。在按鈕單擊事件的第一行中設置斷點。該程序正在使用Windows應用程序 vb.net 2008.點擊按鈕時未觸發事件

如果我運行應用程序,當我點擊按鈕時,它不會觸發按鈕的單擊事件。幫我糾正。

這裏是我的代碼:

Dim reqFTP As FtpWebRequest 
Dim filepath As String 
Dim filename As String 
Dim filename1 As String 
Dim ftpserverip As String 
Dim ftpuserid As String 
Dim ftpPassword As String 
Try 
    filename1 = TxtRemoteFile.Text 
    filepath = TxtLocalFile.Text 
    filename = Locfname.Text 
    ftpserverip = TxtServerIP.Text 
    ftpuserid = TxtUserName.Text 
    ftpPassword = TxtPwd.Text 

    Dim outputStream As FileStream = New FileStream((filepath + ("\\" + filename)), FileMode.Create) 
    reqFTP = CType(FtpWebRequest.Create(New Uri(("ftp://" _ 
         + (ftpserverip + ("/" + filename1))))), FtpWebRequest) 
    reqFTP.Method = WebRequestMethods.Ftp.DownloadFile 
    reqFTP.UseBinary = True 
    reqFTP.Credentials = New NetworkCredential(ftpuserid, ftpPassword) 
    Dim response As FtpWebResponse = CType(reqFTP.GetResponse, FtpWebResponse) 

    Dim ftpStream As Stream = response.GetResponseStream 
    Dim cl As Long = response.ContentLength 
    Dim bufferSize As Integer = 2048 
    Dim readCount As Integer 
    Dim buffer() As Byte = New Byte((bufferSize) - 1) {} 
    readCount = ftpStream.Read(buffer, 0, bufferSize) 

    While (readCount > 0) 
     outputStream.Write(buffer, 0, readCount) 
     readCount = ftpStream.Read(buffer, 0, bufferSize) 

    End While 
    ftpStream.Close() 

    outputStream.Close() 
    response.Close() 

Catch ex As Exception 
    MessageBox.Show(ex.Message) 
End Try 

在運行時,當我點擊控制沒有進入到一個點擊事件

+0

它是一個Web應用程序嗎?雙擊Visual Studio中的按鈕,然後在那裏輸入代碼。 – Cerveser 2012-02-24 10:01:39

+0

你會去清楚地閱讀問題.... – Fernando 2012-02-24 10:20:56

+0

你有沒有嘗試設置按鈕AutoPostBack屬性設置爲true? – user959631 2012-02-24 10:53:53

回答

1

的按鈕,它可能是你的代碼是不是在正確的處理程序。

雙擊表單上的按鈕,並確保代碼存在於此。如果沒有,只是簡單地複製並粘貼。

希望這有助於!

相關問題