asp.net neatUpload 支援大檔案上傳組件

來源:互聯網
上載者:User

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>

地址下載,裡面有詳細的使用文檔

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.