c# asp.net大文件上传(大于1G)

qishao45741100 qishao45741100 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如题,如何使用C#和ASP.net实现大文件的上传,这个文件的容量的很大的,基本都是要对大于1G的文件处理,希望有高手过来指点下?下面是下载的一个代码,不过是多文件的上传,而且效率不高.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

//51aspx
namespace MutiFileUpload
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int FileNum = 0;
string filepath = Server.MapPath("./") + "UploadFile";
string filename = DateTime.Now.ToString("yyyyMMddHHmmss");
HttpFileCollection hfc = Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];

if (hfc[i].ContentLength > 0)
{
hpf.SaveAs(filepath + "/" + filename + System.IO.Path.GetFileName(hpf.FileName));
FileNum++;
}
else
{
//Response.Write(alert("请选择你要上传的文件!"));
//跳出for循环
i = hfc.Count;
break;
}
}
// Response.Write("<script>alert('上传成功!')</script>");
Response.Write("共上传成功的文件个数为:" + FileNum + "个");
FileNum = 0;
}
}
}
但是上面这段程序也有个问题,脚本不能运行,我想知道原因是什么??
...全文

相关推荐

评论 65
收藏 已收藏
分享
返回顶部
qishao45741100
.NET社区 62,271 成员 668,968 内容