一般10M以下的文件上传通过设置Web.Config,再用VS2005自带的FileUpload控件就可以了,但是如果要上传100M甚至1G的文件就不能这样上传了,这时可以用NeatUpload来上传,步骤如下:
1,在工具箱中添加Brettle.Web.NeatUpload.dll,方法:打开VS2005--->点击'工具箱'--->选中一项,如:'常规'这项--->单击右键--->在弹出的菜 单中选'选择项'--->在弹出的窗口中选择'浏览'--->找到'Brettle.Web.NeatUpload.dll'这个文件 --->按确定就添加上了,这时工具箱中多出几个控件出来,有InputFile,progressbar 等,我们主要用这两个.
2.复制文件夹NeatUpload到根目录.
3.拖放使用上传控件InputFile和进度条ProgressBar,添加上传文件的按钮.aspx页面代码如下:
</html>
4.给上传按钮添加Upload_Click事件:
protected void Upload_Click(object sender, EventArgs e)
{
if (AttachFile.HasFile)
{
string FileName = this.AttachFile.FileName;//获取上传文件的文件名,包括后缀
string ExtenName = System.IO.Path.GetExtension(FileName);//获取扩展名
string SaveFileName = System.IO.Path.Combine(
System.Web.HttpContext.Current.Request.MapPath("UpLoads/"),
DateTime.Now.ToString("yyyyMMddhhmm") + ExtenName);//合并两个路径为上传到服务器上的全路径
AttachFile.MoveTo(SaveFileName, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);
string url = "UpLoads/" + DateTime.Now.ToString("yyyyMMddhhmmss") + ExtenName; //文件保存的路径
float FileSize = (float)System.Math.Round((float)AttachFile.ContentLength / 1024000, 1); //获取文件大小并保留小数点后一位,单位是M
}
}
5.注意,要还在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>
<httpModules>
<!--上传大文件-->
<add name="UploadHttpModule"
type="Brettle.Web.NeatUpload.UploadHttpModule,Brettle.Web.NeatUpload"/>
</httpModules>
<!--useHttpModule="true" 设为true时才能看到上传状态,默认是False-->
<neatUpload useHttpModule="true" maxNormalRequestLength="1048576" maxRequestLength="1048576" defaultProvider="FilesystemUploadStorageProvider">
<providers>
<add name="FilesystemUploadStorageProvider"
type="Brettle.Web.NeatUpload.FilesystemUploadStorageProvider, Brettle.Web.NeatUpload"/>
</providers>
</neatUpload>
<httpRuntime maxRequestLength="1048576" executionTimeout="3600"/>
</system.web>
</configuration>
最后这里是上面需要的文件和dll文件的源代码以及怎样用的例子