Imports System.Net
Imports System.IO
Public Class RunExeClient
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call WebClientUploadFileFixError405()
End Sub
'Fix Bug WebClient.UploadFile
'HTTP Error 405.0 - Method Not Allowed
Protected Sub WebClientUploadFileFixError405()
Dim file As Object
For Each f As String In Request.Files.AllKeys
file = Request.Files(f)
file.SaveAs(Server.MapPath("/TestKM/") & file.FileName)
Next
End Sub
Protected Sub btnWriteFile2Server_Click(sender As Object, e As EventArgs) Handles btnWriteFile2Server.Click
Dim webClient As New WebClient 'webClient.Credentials = New NetworkCredential("Admin", "หน้าหม้อ")
AddHandler webClient.UploadProgressChanged, AddressOf UploadProgressChanged
AddHandler webClient.UploadFileCompleted, AddressOf UploadfileCompleted
'Fix bug Error 405 Call WebClient Call Sub WebClientUploadFileFixError405
'End with dummy.aspx is required
webClient.UploadFile(New Uri("http://www.JapanGirl.com/TestKM/RunExeClient.aspx"), "POST", "D:\จิ๋มใหญ่.txt")
End Sub
Protected Sub btnWriteFile2Client_Click(sender As Object, e As EventArgs) Handles btnWriteFile2Client.Click
Dim webClient As New WebClient()
AddHandler webClient.DownloadFileCompleted, AddressOf DownloadFileCompleted
AddHandler webClient.DownloadProgressChanged, AddressOf DownloadProgressChanged
webClient.DownloadFileAsync(New Uri("http://www.JapanGirl.com:4226/TestKM/FileServerToClient.txt"), "c:\จิ่๋มงาม.txt")
End Sub
' Occurs when an asynchronous download operation successfully transfers some or all of the data.
Private Sub DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
'Update progress bar
'
'อมก๋อย
'
End Sub
' Occurs when an asynchronous file download operation completes.
Private Sub DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
'
'อมก๋อย
'
End Sub
Private Sub UploadProgressChanged(ByVal sender As Object, ByVal e As UploadProgressChangedEventArgs)
'
'อมก๋อย
'
End Sub
Private Sub UploadfileCompleted(ByVal sender As Object, ByVal e As UploadFileCompletedEventArgs)
'
'อมก๋อย
'
End Sub
End Class