Asp.net neatupload supports large File Upload components

Source: Internet
Author: User

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

Related Article

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.