NeatUpload的安装使用
?
版本:NeatUpload-1.2.32,用于文件上傳。可傳大文件。
?
1.在VS工具箱中點右鍵選“選擇項”……?將Brettle.Web.NeatUpload.dll添加到工具箱。
可以在添加后的工具箱看到相應控件。
?
2.新建web項目。將NeatUpload復制到項目根目錄。
3.修改Web.config
| <?xml version="1.0" encoding="utf-8"?> ? <configuration> ? ??? <configSections> ??????? <sectionGroup name="system.web"> ??????????? <section name="neatUpload" type="Brettle.Web.NeatUpload.ConfigSectionHandler, Brettle.Web.NeatUpload" allowLocation="true" /> ??????? </sectionGroup> ??? </configSections> ? ??? <appSettings/> ??? <connectionStrings/> ? ??? <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> ??????? <compilation debug="false"> ??????? </compilation> ??????? <authentication mode="Windows" /> ??????? <httpModules> ??????????? <!--如果不加這httpmodules,進度條不顯示--> ???????????<add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule, Brettle.Web.NeatUpload"/> ??????? </httpModules> ??? </system.web> ??? <location path="Default.aspx" > ??????? <system.web> ??????????? <neatUpload useHttpModule="true" /> ??????????? <httpRuntime maxRequestLength="2097151" executionTimeout="3600" useFullyQualifiedRedirectUrl="true" /> ??????? </system.web> ??? </location> </configuration> ? |
?
現在可以拖拽控件開始編程了。
4.aspx頁面代碼如下:
| <head runat="server"> ??? <title> NeatUpload </title> ??? <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> </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:ProgressBar ID="pbProgressBar" runat='server' Inline="true" Width="280px" ?????????????? Height="50px"> ?????? </Upload:ProgressBar> ?? </div> ?? </div> ??? </form> </body> </html> ? |
設計頁面如下:
?
5.按鈕事件處理函數:
| 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; ??????????????? } ??????????? } ??????? } |
?
做到這里程序就可以運行的了。
默認的進度條的樣式是可以修改的。
主要修改default.css、Progress.aspx及ProgressBar控件的屬性。
?
default.css修改部分:
| .ProgressDisplay .ProgressBar { ???? ?background-color: #D7E5F7; ???? ?background-image: url("/11.gif");?/*進度條背景圖片*/ ???? ?height:20px; } #normalInProgress{ ???? color: Red;????? /*進度條字體顏色*/ } #completed{ ???? color:Blue;?? /*上傳完成的字體顏色*/ } ? |
Progress.aspx是顯示進度條的核心文件,相關數據的顯示都在里面。
| <td id="barTd" > ????????????? <div id="statusDiv" runat="server" class="StatusMessage"> ? ?????????????????? <Upload:DetailsSpan id="normalInProgress" runat="server" WhenStatus="NormalInProgress" style="font-weight: normal; white-space: nowrap;">???????? ??? ???? ??????????????<%-- ?正在上傳時顯示的?? --%> ?????????????????? <%-- <%# FormatCount(BytesRead) %>/<%# FormatCount(BytesTotal) %> <%# CountUnits %> --%> ????????????? ??? (<%# String.Format("{0:0%}", FractionComplete) %>) at <%# FormatRate(BytesPerSec) %> ?????????????????? <%-- - <%# FormatTimeSpan(TimeRemaining) %> left??????? --%> ?????????????????? </Upload:DetailsSpan> ? ?????????????????? <Upload:DetailsSpan id="chunkedInProgress" runat="server" WhenStatus="ChunkedInProgress" style="font-weight: normal; white-space: nowrap;">??????? ?????????????????? ?<%# FormatCount(BytesRead) %> <%# CountUnits %> ?????????????????????? at <%# FormatRate(BytesPerSec) %> ?????????????????????? - <%# FormatTimeSpan(TimeElapsed) %> elapsed ?????????????????? </Upload:DetailsSpan> ?????????????????? <Upload:DetailsSpan id="completed" runat="server" WhenStatus="Completed"> ?????????????????????? <%-- ?上傳完成時顯示的?? --%> 完成了: <%# FormatCount(BytesRead) %> <%# CountUnits %> ?????????????????????? at <%# FormatRate(BytesPerSec) %> ?????????????????????? took <%# FormatTimeSpan(TimeElapsed) %> ?????????????????? </Upload:DetailsSpan> ?????????????????? <Upload:DetailsSpan id="cancelled" runat="server" WhenStatus="Cancelled"> ?????????????????????? Cancelled! ?????????????????? </Upload:DetailsSpan> ?????????????????? <Upload:DetailsSpan id="rejected" runat="server" WhenStatus="Rejected"> ?????????????????????? Rejected: <%# Rejection != null ? Rejection.Message : "" %> ?????????????????? </Upload:DetailsSpan> ?????????????????? <Upload:DetailsSpan id="error" runat="server" WhenStatus="Failed"> ?????????????????????? Error: <%# Failure != null ? Failure.Message : "" %> ?????????????????? </Upload:DetailsSpan> ?????????????????? <Upload:DetailsDiv id="barDetailsDiv" runat="server" UseHtml4="true" ?????????????????????? ?Width='<%# Unit.Percentage(Math.Floor(100*FractionComplete)) %>' class="ProgressBar"></Upload:DetailsDiv>? ????????????? </div> ???????? </td> |
?
程序的效果圖如下:
上傳前:
?
上傳中:
?
上傳結束:
?
轉載于:https://www.cnblogs.com/langlang/archive/2009/12/11/1621730.html
總結
以上是生活随笔為你收集整理的NeatUpload的安装使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 质量糟糕的代码会在项目中像病毒一样传播,
- 下一篇: 【原创】A进程窗口嵌入到B进程窗口中显示