1. Add brettle. Web. neatupload. DLL to the toolbox. You can see the inputfile and other controls in the toolbox.
2. Copy the folder neatupload to the root directory.
3. Drag and Drop the upload control inputfile and progress bar to add the Upload File button. ASPX pageCodeAs follows:
Copy code The Code is as follows: <body>
<Form ID = "form1" runat = "server">
<Div>
<Upload: inputfile id = "attachfile" runat = "server"> </upload: inputfile>
<Asp: button id = "Upload" runat = "server" text = "Upload" onclientclick = "togglevisibility ('ssssbar', 'on')" onclick = "upload_click"/>
<Div id = "progressbar" style = "display: none;">
<Upload: progressbar id = "pbprogressbar" runat = "server" inline = "true" width = "500px" Height = "100"> </upload: progressbar>
</Div>
</Div>
</Form>
</Body>
4. Add the togglevisiblity function of the script code to the page as follows:Copy codeThe Code is as follows: <SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function togglevisibility (ID, type)
{
El = Document. getelementbyid (ID );
If (El. Style)
{
If (type = 'on ')
{
El. style. Display = 'block ';
}
Else
{
El. style. Display = 'none ';
}
}
Else
{
If (type = 'on ')
{
El. Display = 'block ';
}
Else
{
El. Display = 'none ';
}
}
}
</SCRIPT>
5. Add the event upload_click to the Upload File button.
Copy code The Code is as follows: protected void upload_click (Object sender, eventargs E)
{
String filename = This. attachfile. filename; // obtain the full path of the uploaded file
String extenname = system. Io. Path. getextension (filename); // get the extension
String savefilename = system. io. path. combine (request. physicalapplicationpath, datetime. now. tostring ("yyyymmddhhmm") + extenname); // merge the two paths to the full path uploaded to the server.
If (this. attachfile. contentlength> 0)
{
Try
{
This. attachfile. moveTo (savefilename, brettle. Web. neatupload. movetooptions. Overwrite );
}
Catch (exception ex)
{
Throw ex;
}
}
}
6. Add the HTTP module declaration in the configuration file web. config:Copy codeThe Code is as follows: <Add name = "uploadhttpmodule" type = "brettle. Web. neatupload. uploadhttpmodule, brettle. Web. neatupload"/>
</Httpmodules>
7. Make other settings in Web. config to ensure perfection.
Add in <configuration>Copy codeThe Code is as follows: <configsections>
<Sectiongroup name = "system. Web">
<Section name = "neatupload" type = "brettle. Web. neatupload. configsectionhandler, brettle. Web. neatupload" allowlocation = "true"/>
</Sectiongroup>
</Configsections>
AddCopy codeThe Code is as follows: <neatupload usehttpmodule = "false" maxnormalrequestlength = "4096" maxrequestlength = "2097151" defaultprovider = "filesystemuploadstorageprovider">
<Providers>
<Add name = "filesystemuploadstorageprovider" type = "brettle. Web. neatupload. filesystemuploadstorageprovider, brettle. Web. neatupload"/>
</Providers>
</Neatupload>
Add the following position in <configuration>Copy codeThe Code is as follows: <Location Path = "default. aspx">
<System. Web>
<Neatupload usehttpmodule = "true"/>
<Httpruntime maxrequestlength = "2097151" executiontimeout = "3600" usefullyqualifiedredirecturl = "true"/>
</System. Web>
</Location>
</Configuration>
Address download, which contains detailed usage documents