Brettle.Web.NeatUpload.dll支持的大文件上传
Brettle.Web.NeatUpload.dll支持的大文件上传
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 useFullyQualifiedRedirectUrl="true">
<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>
最后这里是上面需要的文件和dll文件的源代码以及怎样用的例子
Brettle.Web.NeatUpload.dll源代码
NeatUpload文件夹
NeatUpload.dll Demo
注意的问题:
例如:标记 " <select > " 前面的 " <sel "等变为乱码,导致后面的一串代码完全显示在网页上。
1.大都是DropDownList生成的select 或 RadioButtonList生成的table出现乱码。
2.偶尔出现,刷新一下就好了。
3.之前网站中javascript、css等文件,有部分是ANSI格式保存,后改为UTF-8保存,乱码出现几率大大下降。
4.中文网站,但并无中文变为乱码的现象。
5.Web.Config中的设置为 <globalization requestEncoding= "utf-8 " responseEncoding= "utf-8 " fileEncoding= "utf-8 "/ >
结论:不是什么编码问题。是上传组件Brettle.Web.NeatUpload的问题。在.config中加入了一句:
<httpModules >
<add name= "UploadHttpModule " type= "Brettle.Web.NeatUpload.UploadHttpModule, Brettle.Web.NeatUpload "/ >
</httpModules >
据分析,这个组件在页面比较大的时候会有截断源代码的行为!
大家以后用其它组件一定要注意了!