日期:2014-05-17  浏览次数:20912 次

ASP.NET上传大文件
上网下一个neatupload 1.2.32的压缩包:(附压缩包)
准备:
  将压缩包中的Brettle.Web.NeatUpload.dll、Brettle.Web.NeatUpload.HashedInputFile.dll、Hitone.Web.SqlServerUploader.dll三个文件放到项目的Bin目录下(不确定这三个文件是否全都要用上,不管了,都用是没错的),然后对这三个文件添加引用.
  将压缩包中的NeatUpload文件夹复制到项目的根目录下.
  添加工具箱->选择项->浏览->选择刚复制的Brettle.Web.NeatUpload.dll文件,工具箱中就将添加相应的工具了.我测试用了两个:InputFile和ProgressBar.
修改Web.config文件
<configuration>
    <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="neatUpload" type="Brettle.Web.NeatUpload.ConfigSectionHandler, Brettle.Web.NeatUpload" allowLocation="true" />  <!-- NeatUpload添加配置(第一处) -->
    </sectionGroup>
</configuration>
<system.web>
    <httpModules>
        <add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule, Brettle.Web.NeatUpload" /> <!-- NeatUpload添加配置(第二处) -->
    </httpModules>
</system.web>
测试:
前台:
<head runat="server">
    <title>上传测试</title>
    <script type="text/javascript">
        function ToggleVisibility(id,type){
            var 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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <Upload:InputFile ID="AttachFile" runat="server" />
        <asp:Button ID="Upload" runat="server" Text="Upload" OnClientClick="ToggleVisibility('ProgressBar','on')" OnClick="Upload_Click" />
        <div id="ProgressBar">
            <upload:pro