Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
HTTP Upload with Progress Monitoring EventsThe Chilkat Upload component is freeware. This example demonstrates how to HTTP upload one or more files and monitor the progress with event callbacks. Formal support for the Chilkat Upload component is included with a "Chilkat Bundle" purchase.
' Private WithEvents upload As Chilkat.Upload Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click upload = New Chilkat.Upload() ' Make sure the EnableEvents property is set to true, otherwise we ' won't receive event callbacks. upload.EnableEvents = True ' Call AbortCheck every 100 milliseconds. upload.HeartbeatMs = 100 ' To upload more than one file, call AddFileReference multiple times -- ' once for each file to be uploaded. ' The formElementName is arbitrary, and can be anything. Dim formElementName As String = "file1" ' The localFilename is a file that exists on your local filesystem. Dim localFilename As String = "hamlet.xml" upload.AddFileReference(formElementName, localFilename) ' The Hostname and Path properties specify the server-side ' page/program/script/CGI that will recieve and process the upload. upload.Hostname = "www.freeaspupload.net" upload.Path = "/freeaspupload/testUpload.asp" ' The BlockingUpload call does not return until all the files have been ' uploaded (or an error occurs or the upload is aborted by the application). Dim success As Boolean = upload.BlockingUpload() If success = False Then textBox1.Text = upload.LastErrorText Else ' When BlockingUpload returns true, it indicates that the files/data have ' been uploaded and an HTTP response status indicating success was ' received. If the success/failure of an uploaded is indicated by ' a message in the HTTP response body, you may access it via ' the ResponseBody property (which is a byte array). textBox1.Text = System.Text.UTF8Encoding.UTF8.GetString(upload.ResponseBody) MessageBox.Show("Success!") End If End Sub ' The Chilkat.Upload.HeartbeatMs property determines the interval at which ' AbortCheck events are called. If HeartbeatMs is set to 0 (the default), ' then no AbortCheck events are called. This example sets the HeartbeatMs = 100 ' milliseconds. Private Sub upload_OnAbortCheck(ByVal sender As Object, ByVal args As Chilkat.AbortCheckEventArgs) Handles upload.OnAbortCheck ' Update progressBar2 so we can visually see the heartbeat. If (ProgressBar2.Value > 90) Then ProgressBar2.Value = 0 Else ProgressBar2.Value += 10 End If ' Handle UI events to keep the user-interface responsive. System.Windows.Forms.Application.DoEvents() ' To abort the upload while in progress, set the ' args.Abort property = true, like this: ' args.Abort = true; End Sub ' Progress monitor callback -- called each time the percentage completion ' updates to a larger value. Private Sub upload_OnPercentDone(ByVal sender As Object, ByVal args As Chilkat.PercentDoneEventArgs) Handles upload.OnPercentDone ' args.PercentDone is an integer value between 1 and 100. ProgressBar1.Value = args.PercentDone End Sub |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.