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 ();
}
}
}