In ASP. NET, there are many file uploads. The so-called upload has two meanings: the first is to save the file in the database; the second is to save the file in
Under a specified folder;
Today we will introduce you to a simple multi-File Upload method. You can use the JQ plugin plug-in to upload files. This file upload method is simple and flexible.
You can complete most of the upload tasks by configuring attributes:
Project directory list:
Step 1: Introduce jquery-related JS files:
< Script SRC = "Jquery/jquery-1 [1]. 3.2-vsdoc2.js" Type = "Text/JavaScript"> </ Script > -- This is a JS file intelligently sensed by vs2008 < Script SRC = "Jquery/jquery-1 [1]. 3.2.js" Type = "Text/JavaScript"> </ Script > --- Here, the internal library file in JQ, Version 1.3.2 < Script SRC = "Jquery/jquery. Multifile. js" Type = "Text/JavaScript"> </ Script >
---- This is the JQ plugin file.
Note: Except for the first file, all the above three files must be referenced in your page file,ProgramIn order to run properly;
Step 2: add the fileupload File Upload control and an upload button;
< Fieldset Style =" Height : 94px ; Width : 359px "> < Legend > Jquery multi-File Upload </ Legend > < ASP : Fileupload ID = "Upfile" Runat = "Server" Class = "Multi" Maxlength = "2"/> < ASP : Button ID = "Btnupload" Runat = "Server" Text = "Upload all"
Onclick= "Btnupload_click"/> </Fieldset>
Description: you can configure attributes for the fileupload upload control. Description of attributes:
Attribute name |
Description |
Use Cases |
Class |
Upload type |
Class = multi |
Maxlength |
Number of uploaded files |
Maxlength = 3 |
Accept |
Accepted file types |
Accept = JPG | RAR |
|
|
|
You can also customize the style of the Upload File List. Here, I will not come out in one fell swoop,
Step 3: Compile and uploadCode:
Protected void Btnupload_click ( Object Sender, Eventargs E ){ Try { Httpfilecollection HFCs = request. files; For ( Int I = 0; I Httppostedfile HPF = hfc[ I]; If (HPF. contentlength> 0) {HPF. saveas (server. mappath ( "Myfile" ) + "\\" + System. Io. Path . Getfilename (HPF. filename); response. Write ( "<SCRIPT> alert ('file uploaded successfully! ') </SCRIPT>" );}}} Catch ( Exception Ex ){ Throw Ex ;}}
Step 4: running effect:
From the running effect, we can see that when the number of files you upload is equal to the size of your attribute settings, the browsing of the upload control will become unavailable;
This greatly simplifies the coding time;
Although this articleArticleVery simple, but I hope it will help you in future projects;
Has any friends in the garden studied how the QQ space uploads images? I always wanted to study it and didn't find any
I hope that my friends in the garden can provide some information about uploading QQ space images. Thank you very much: