C# Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

C# Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
RSA Encryption
S/MIME
Socket
Spider
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
String
Byte Array
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

HTTP Asynchronous Upload

The Chilkat Upload component is freeware. This example demonstrates how to HTTP upload one or more files asynchronously in a background thread and monitor the progress (and potentially abort the upload prior to it finishing). Formal support for the Chilkat Upload component is included with a "Chilkat Bundle" purchase.

Download Chilkat .NET for 2.0 Framework

Download Chilkat .NET for 1.0 / 1.1 Framework

//  
// This example demonstrates how to HTTP upload one or more files
// asynchronously in a background thread.
private void button2_Click(object sender, EventArgs e)
{
    Chilkat.Upload upload = new Chilkat.Upload();

    // 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.  
    string formElementName = "file1";
    // The localFilename is a file that exists on your local filesystem.
    string localFilename = "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";

    // Start the upload in a background thread.
    bool success = upload.BeginUpload();
    if (success == false)
    {
        textBox1.Text = upload.LastErrorText;
        return;
    }

    // Note: When doing asynchronous uploads, there are no event callbacks.
    // Event callbacks only occur when doing synchronous uploads via the 
    // BlockingUpload method.


    // Wait for the upload to finish.
    // Update the progress as we wait.
    while (upload.UploadInProgress)
    {
        // We can abort the upload at any point by calling:
        // upload.AbortUpload();

        // Display the percentage complete and the number of bytes uploaded so far..
        label1.Text = Convert.ToString(upload.PercentUploaded) + "% complete";
        label2.Text = Convert.ToString(upload.NumBytesSent) + " bytes uploaded...";

        // Show the percentage completion in a progress bar.
        progressBar1.Value = (int)upload.PercentUploaded;

        // The total upload size will become set after the upload begins:
        label3.Text = "Total Upload Size (in bytes) = " + Convert.ToString(upload.TotalUploadSize);

        // Sleep 1/10th of a second.
        upload.SleepMs(100);

        // Handle UI events.
        System.Windows.Forms.Application.DoEvents();
    }

    // Did the upload succeed?
    if (upload.UploadSuccess)
    {
        MessageBox.Show("Success!");
    }
    else
    {
        MessageBox.Show(upload.LastErrorText);
    }


}

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Email Component · XML Parser