I have compiled a multi-file upload function and shared it with you. For more information, see.
Page:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" validaterequest = "false" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> untitled page </title>
<SCRIPT type = "text/JavaScript">
// Add a client nearby
Function AddFile (){
VaR STR = '<input type = "file" name = "file"/> <input type = "button" value = "Remove" onclick = "remove (this) "/> <br/> ';
Document. All. Files. insertadjacenthtml ("beforeend", STR );
}
// Near the client Deletion
Function remove (OBJ ){
OBJ. style. Display = "NONE ";
OBJ. nextsibling. style. Display = "NONE ";
OBJ. previussibling. style. Display = "NONE ";
OBJ. previussibling. Disabled = "disabled ";
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Div id = "Files">
<% -- There must be an Asp.net server fileupload control -- %>
Multifile upload <br/>
<Asp: fileupload id = "fileupload1" runat = "server"/> <input type = "button" value = "Remove" onclick = "remove (this) "/> <br/>
</Div>
<Input id = "button1" type = "button" value = "add" onclick = "AddFile ()"/>
<Input id = "button2" type = "button" value = "reset" onclick = "This. Form. Reset ()"/>
<Asp: button id = "button3" runat = "server" onclick = "button3_click" text = "Upload" causesvalidation = "false"/> </div>
</Form>
</Body>
</Html>
CodePart:
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. IO;
Using system. net;
Using system. text;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
}
Protected void button3_click (Object sender, eventargs E)
{
Httpfilecollection filelist = httpcontext. Current. Request. files;
// Httpfilecollection filelist = request. files;
Stringbuilder strb = new stringbuilder ();
For (INT I = 0; I <filelist. Count; I ++)
{
Httppostedfile file = filelist [I];
String filename = path. getfilename (file. filename );
String fileextension = path. getextension (filename );
If (file. contentlength> 0)
{
File. saveas (server. mappath ("upload/" + filename ));
Strb. append (string. Format ("file {0} uploaded successfully, extension: {1} \ n", filename, fileextension ));
}
}
// Prompts the upload status
Clientscript. registerclientscriptblock (typeof (PAGE), "", "alert ('" + strb. tostring () + "')", true );
}
}