下載neatupload的免費版本 http://neatupload.codeplex.com/html
訪問地址http://www.brettle.com/Demo.aspx查看相應的Demo示例;
web
將下載下來的文件解壓之後,將Brettle.Web.NeatUpload.dll添加到工具箱,ajax
將裏面的NeatUpload文件夾複製到項目根目錄,接着修改web.config的配置文件服務器
在Web.config的system.web節點中寫入下面的配置ide
<httpModules>
<add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule, Brettle.Web.NeatUpload" />
</httpModules>
<httpRuntime maxRequestLength="400000" executionTimeout="3600" />工具
.aspx代碼以下:this
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebFile2.WebForm1" %>url
<%@ Register assembly="Brettle.Web.NeatUpload" namespace="Brettle.Web.NeatUpload" tagprefix="Upload" %>spa
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<Upload:InputFile ID="AttachFile" runat="server" />
<Upload:ProgressBar ID="ProgressBar1" runat="server" />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<br />
<br />
<Upload:MultiFile ID="MultiFile1" runat="server">
</Upload:MultiFile>
</div>
</form>
</body>
</html>
.CS代碼以下:
protected void Button1_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
}
}