下载neatupload的免费版本 http://neatupload.codeplex.com/
访问地址http://www.brettle.com/Demo.aspx查看相应的Demo示例;
将下载下来的文件解压以后,将Brettle.Web.NeatUpload.dll添加到工具箱,
将里面的NeatUpload文件夹复制到项目根目录,接着修改web.config的配置文件
在Web.config的system.web节点中写入下面的配置
<httpModules>
<add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule, Brettle.Web.NeatUpload" />
</httpModules>
<httpRuntime maxRequestLength="400000" executionTimeout="3600" />
.aspx代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebFile2.WebForm1" %>
<%@ Register assembly="Brettle.Web.NeatUpload" namespace="Brettle.Web.NeatUpload" tagprefix="Upload" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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
}
}
转载于:https://blog.51cto.com/1906754/742609