欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net neatUpload 支持大文件上传组件

程序员文章站 2024-03-11 21:15:25
1.在工具箱中添加brettle.web.neatupload.dll,可以看到工具箱中出现inputfile等控件。 2.复制文件夹neatupload到根目录. 3.拖...

1.在工具箱中添加brettle.web.neatupload.dll,可以看到工具箱中出现inputfile等控件。
2.复制文件夹neatupload到根目录.
3.拖放使用上传控件inputfile和进度条progressbar,添加上传文件的按钮.aspx页面代码如下:

复制代码 代码如下:

<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('progressbar','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.添加脚本代码togglevisiblity函数到页面上如下:
复制代码 代码如下:

<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.给上传文件的按钮添加事件upload_click

复制代码 代码如下:

protected void upload_click(object sender, eventargs e)
{
string filename = this.attachfile.filename;//获取上传文件的全路径
string extenname = system.io.path.getextension(filename);//获取扩展名
string savefilename = system.io.path.combine(request.physicalapplicationpath, datetime.now.tostring("yyyymmddhhmm") + extenname);//合并两个路径为上传到服务器上的全路径
if (this.attachfile.contentlength > 0)
{
try
{
this.attachfile.moveto(savefilename, brettle.web.neatupload.movetooptions.overwrite);
}
catch (exception ex)
{
throw ex;
}
}
}

6.在配置文件web.config中添加http模块声明:
复制代码 代码如下:

<httpmodules>
<add name="uploadhttpmodule" type="brettle.web.neatupload.uploadhttpmodule, brettle.web.neatupload" />
</httpmodules>


7.需要在web.config进行其他一些设置才能保证完美。
在<configuration>里面加入
复制代码 代码如下:

<configsections>
<sectiongroup name="system.web">
<section name="neatupload" type="brettle.web.neatupload.configsectionhandler, brettle.web.neatupload" allowlocation="true" />
</sectiongroup>
</configsections>

在 <system.web>加入
复制代码 代码如下:

<neatupload usehttpmodule="false" maxnormalrequestlength="4096" maxrequestlength="2097151" defaultprovider="filesystemuploadstorageprovider">
<providers>
<add name="filesystemuploadstorageprovider" type="brettle.web.neatupload.filesystemuploadstorageprovider, brettle.web.neatupload" />
</providers>
</neatupload>

在<configuration>里面的后面位置加入
复制代码 代码如下:

<location path="default.aspx" >
<system.web>
<neatupload usehttpmodule="true" />
<httpruntime maxrequestlength="2097151" executiontimeout="3600" usefullyqualifiedredirecturl="true" />
</system.web>
</location>
</configuration>

地址下载,里面有详细的使用文档