Multi-File Upload example source code (various types including images are supported by default)

Source: Internet
Author: User

 
A simple example of image uploading (watermarking, thumbnails, and remote storage) was published in the garden a few days ago, this type re-releases the source code of a Multifile upload example (various types including images are supported by default). You can upload files (including images) in batches at the same time)

There are many examples of File Uploading in the garden, but there are no complete examples.CodeI sorted it out and released it. This is more intuitive and I hope it will help you.

Development Environment vs2005

Download the source code

Some source code

  Public Partial Class _ Default: system. Web. UI. Page
{
Static   Public Arraylist =   New Arraylist (); // Save the file list
Public   Int Filesuploaded =   0 ; // Number of uploaded files

Protected   Void Page_load ( Object Sender, eventargs E)
{

}
/**/ ///   <Summary>
/// Add the file to be uploaded to ListBox
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>

Protected   Void Addfile_click ( Object Sender, eventargs E)
{
If (Page. ispostback =   True )
{
ICF. Add (findfile );
Filelist. Items. Add (findfile. postedfile. filename );
}
Else
{}

}

/**/ ///   <Summary>
/// Delete a specified object from ListBox
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Protected   Void Remvfile_click ( Object Sender, eventargs E)
{
If (Filelist. selectedindex =   - 1 )
{
Tipinfo. Text= "Error-the object to be deleted must be specified.";
Return;
}
Else   If (Filelist. Items. Count ! =   0 )
{
Conditioned. removeat (filelist. selectedindex );
Filelist. Items. Remove (filelist. selecteditem. Text );
Tipinfo. Text= "";
}

}

/**/ /// <Summary>
///Upload objects in ListBox cyclically to the specified folder
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Public   Void Upload_serverclick ( Object Sender, system. eventargs E)
{
String Baselocation = Server. mappath ( " Uploadfiles/ " ); // Upload path
String Status =   "" ; // List of objects displayed after successful upload

If (Filelist. Items. Count =   0 ) && (Filesuploaded =   0 ))
{
Tipinfo. Text= "Error-the file to be uploaded must be specified.";
Return;
}
Else
{
Foreach (System. Web. UI. htmlcontrols. htmlinputfile In )
{
Try
{
String FN = System. Io. Path. getfilename (guid. postedfile. filename );
Conditioned. postedfile. saveas (baselocation + FN );
Filesuploaded ++ ;
Status + = FN +   " <Br> " ;
}
Catch (Exception ERR)
{
Tipinfo. Text =   " Upload Error "   + Baselocation
+   " <Br> "   + Err. tostring ();
}
}

If (Filesuploaded = (Count)
{
Tipinfo. Text =   " Uploaded in total "   + Filesuploaded +   " Files. <Br> "   + Status;
}
Guid. Clear ();
Filelist. Items. Clear ();
}

}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.