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 个解决方案
#1
asp.net iis 都有大小限制的, 是否能配置到支持 1 G 的不知道,
你需要处理断线后的续传问题.
你需要处理断线后的续传问题.
#2
if (fupUrl.PostedFile.ContentLength > 1024000)
{
fileOk = false;
Helper.CommonTools.AlertInfo("上传的作品大小不能超过3M!", "Upload.aspx");
return;
}
{
fileOk = false;
Helper.CommonTools.AlertInfo("上传的作品大小不能超过3M!", "Upload.aspx");
return;
}
#3
考虑用其他的吧!比如Flex,Ocx什么的好点吧?
#4
我现在的要求就是要处理大文件的上传问题,小于1G的都没什么用,而且怎么处理超过1G的断点后续上传问题
#5
路过学习
#6
system.web> </system.web>之间
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="21000" executionTimeout="300" />
maxRequestLength:设置上传文件的最大值,单位:KB。(默认是4096KB,即4M)
executionTimeout:设置超时时间,单位:秒。(默认是90秒)
用HttpWorkerRequest,GetPreloadedEntityBody 和 ReadEntityBody方法从IIS为ASP.NET建立的pipe里分块读取数据
http://topic.csdn.net/u/20091029/09/e5dc6f96-f1fb-4b61-b68d-546622b4b3e3.html
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="21000" executionTimeout="300" />
maxRequestLength:设置上传文件的最大值,单位:KB。(默认是4096KB,即4M)
executionTimeout:设置超时时间,单位:秒。(默认是90秒)
用HttpWorkerRequest,GetPreloadedEntityBody 和 ReadEntityBody方法从IIS为ASP.NET建立的pipe里分块读取数据
http://topic.csdn.net/u/20091029/09/e5dc6f96-f1fb-4b61-b68d-546622b4b3e3.html
#7
你写个函数 用线程分段上传
一下一下上传 不然会卡死的 太大的不行
貌似现在又大文件上传的控件
自己写一个比较好
一下一下上传 不然会卡死的 太大的不行
貌似现在又大文件上传的控件
自己写一个比较好
#8
Setting up Web.config to allow uploading of large files by ASP .NET applications
This article shows how to setup Web.config to allow uploading of files larger than 4 MB by ASP.NET applications.
Multiple File Upload With Progress Bar Using Flash and ASP.NET
How to use Flash to upload multiple files in a medium-trust hosting environment
This article shows how to setup Web.config to allow uploading of files larger than 4 MB by ASP.NET applications.
Multiple File Upload With Progress Bar Using Flash and ASP.NET
How to use Flash to upload multiple files in a medium-trust hosting environment
#9
少不了要支持断点续传功能!
#10
ASP.Net file post direct to disk with upload file progress support
This module gives developers a way to intercept multi-part form posts in ASP.Net and store the data directly to disk without going direct to memory. It also provides a way to extract the file progress from an external window. Written in C# for backend, and Javascript / Atlas for the progress bar.
Introduction
ASP.NET is a very nice and fast way to program small to enterprise level websites fast and efficiently. Most controls are perfect for any web development needed however the FileUpload control really has some short comings. Back when I used .net 1.1, I did some testing to see how the control worked and handled large files and was very unpleased.
I tried to upload a huge 1 or 2 gig file. I found myself with a problem where my web page would error, and the memory was never released. I left it at that, and did not mess with it anymore. I though for sure that the 2.0 framework would have fixed that problem but it appears that we were not that lucky (at least not that I could find).
Anyhow the project I was working on requires that I have control of what my users do. You never know when someone is going to try and upload some huge file on purpose or accident.
This module gives developers a way to intercept multi-part form posts in ASP.Net and store the data directly to disk without going direct to memory. It also provides a way to extract the file progress from an external window. Written in C# for backend, and Javascript / Atlas for the progress bar.
Introduction
ASP.NET is a very nice and fast way to program small to enterprise level websites fast and efficiently. Most controls are perfect for any web development needed however the FileUpload control really has some short comings. Back when I used .net 1.1, I did some testing to see how the control worked and handled large files and was very unpleased.
I tried to upload a huge 1 or 2 gig file. I found myself with a problem where my web page would error, and the memory was never released. I left it at that, and did not mess with it anymore. I though for sure that the 2.0 framework would have fixed that problem but it appears that we were not that lucky (at least not that I could find).
Anyhow the project I was working on requires that I have control of what my users do. You never know when someone is going to try and upload some huge file on purpose or accident.
#11
楼上的太强了,看不懂英文。。。。。
#12
帮顶。
#13
呵呵.Up
#14
关注
#15
继点续传没做过,但首先还得解决上传进度的问题吧,我关注
#16
这个东西 我改成了中文的
但是并不能解决 楼主的 上传 1G 的要求
#17
关注。。
#18
http://download.csdn.net/source/675091
LZ 去看看。。。。我没试!!!
好用,记得 发表下。。。
LZ 去看看。。。。我没试!!!
好用,记得 发表下。。。
#19
Mark一下,回头再看
#20
小关注一下
#21
web 上 上传那么大 干什么啊
#22
这个仅仅是一个设置而已
#23
10楼贴的那个类很强大
#24
写这个要支持多用户上传文件而且文件的基本都是大于1G的,虽然在ASP.NET里面可以设置文件上传的大小,不过好像不能达到我的要求,希望高手来解决下
#25
设置只是第一步,第二步用哪个文件上传类试试
#26
关注中
#27
标记一下,等神人出现
#28
1G,怎么会要上传这么大的文件?做FTP吧
#29
我有activex文件上传的控件
#30
支持大文件上传,断点续传
#31
断点续传呗。
把文件分割,用线程分块一段一段的传吧
把文件分割,用线程分块一段一段的传吧
#32
还是分割后上传吧
#33
路过,学习
没有试过这样大的文件上传
没有试过这样大的文件上传
#34
分割上传
#35
路过,学习
#36
mark up
#37
mark
#38
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Text;
using System.Web;
using System.Reflection;
namespace myHttpModule
{
/// <summary>
/// HttpUploadModule 的摘要说明。
/// </summary>
public class HttpUploadModule: IHttpModule
{
public HttpUploadModule()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(this.Application_BeginRequest);
application.EndRequest += new EventHandler(this.Application_EndRequest);
application.Error += new EventHandler(this.Application_Error);
}
public void Dispose()
{
}
private void Application_BeginRequest(Object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
// 如果是文件上传
if (IsUploadRequest(app.Request))
{
// 返回 HTTP 请求正文已被读取的部分。
HttpWorkerRequest request = GetWorkerRequest(app.Context);
Encoding encoding = app.Context.Request.ContentEncoding;
int bytesRead = 0; // 已读数据大小
int read; // 当前读取的块的大小
int count = 8192; // 分块大小
byte[] buffer; // 保存所有上传的数据
byte[] tempBuff = null;
if (request != null)
{
tempBuff = request.GetPreloadedEntityBody();
}
if (tempBuff != null)
{
// 获取上传大小
//
long length = long.Parse(request.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength));
buffer = new byte[length];
count = tempBuff.Length; // 分块大小
// 将已上传数据复制过去
//
Buffer.BlockCopy(tempBuff, 0, buffer, bytesRead, count);
// 开始记录已上传大小
//
bytesRead = tempBuff.Length;
// 循环分块读取,直到所有数据读取结束
//
while (request.IsClientConnected() &&
!request.IsEntireEntityBodyIsPreloaded() &&
bytesRead < length
)
{
// 如果最后一块大小小于分块大小,则重新分块
//
if (bytesRead + count > length)
{
count = (int)(length - bytesRead);
tempBuff = new byte[count];
}
// 分块读取
//
read = request.ReadEntityBody(tempBuff, count);
// 复制已读数据块
//
Buffer.BlockCopy(tempBuff, 0, buffer, bytesRead, read);
// 记录已上传大小
//
bytesRead += read;
}
if (
request.IsClientConnected() &&
!request.IsEntireEntityBodyIsPreloaded()
)
{
// 传入已上传完的数据
//
InjectTextParts(request, buffer);
// 表示上传已结束
}
}
}
}
/// <summary>
/// 结束请求后移除进度信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Application_EndRequest(Object sender, EventArgs e)
{
}
/// <summary>
/// 如果出错了设置进度信息中状态为“Error”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Application_Error(Object sender, EventArgs e)
{
}
HttpWorkerRequest GetWorkerRequest(HttpContext context)
{
IServiceProvider provider = (IServiceProvider)HttpContext.Current;
return (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
}
/// <summary>
/// 传入已上传完的数据
/// </summary>
/// <param name="request"></param>
/// <param name="textParts"></param>
void InjectTextParts(HttpWorkerRequest request, byte[] textParts)
{
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic;
Type type = request.GetType();
while ((type != null) && (type.FullName != "System.Web.Hosting.ISAPIWorkerRequest"))
{
type = type.BaseType;
}
if (type != null)
{
type.GetField("_contentAvailLength", bindingFlags).SetValue(request, textParts.Length);
type.GetField("_contentTotalLength", bindingFlags).SetValue(request, textParts.Length);
type.GetField("_preloadedContent", bindingFlags).SetValue(request, textParts);
type.GetField("_preloadedContentRead", bindingFlags).SetValue(request, true);
}
}
/// <summary>
/// 是否为附件上传
/// 判断的根据是ContentType中有无multipart/form-data
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
bool IsUploadRequest(HttpRequest request)
{
return request.ContentType.ToLower()=="multipart/form-data";
}
}
}
需要在web.config中加入
<httpRuntime executionTimeout="600" maxRequestLength="1048576"/>
<httpModules>
<add name="HttpUploadModule" type="myHttpModule" />
</httpModules>
#39
呵呵,向这样的要求,要买收费的控件才行了。
以前试用过几个,还算不错。
以前试用过几个,还算不错。
#40
一般来说asp.net里只能传大约4mb的东西,但是实际需求下,可以采用很多方式比如flash,好像有个免费的flash可以上传的,lz搜索一下应该可以找到,再不行留个mail我好像有个
#41
需要使用第三方控件,有免费的
#42
通过网页来上传这么大的文件是不可取的,可以专门做个上传工具,或者上传控件,flash,active控件啥的。不过我没搞过~
#43
只能说这样的需求很有变态
#44
slickupload.
#45
mtom协议支持大文件分小块传输
#46
这个是什么控件啊?能告诉一下吗?
#47
http://www.evget.com/zh-CN/FeaturedArticle/Default.aspx?id=1
联系方式:qq 228184703
联系方式:qq 228184703
#48
用NeatUpload上传控件,免费的!上传1G以上的文件没有问题,我曾经做过!但好像不支持断点续传!
#49
#50
我就纳闷了 谁这么有劲啊 老顶 09年的帖子
#1
asp.net iis 都有大小限制的, 是否能配置到支持 1 G 的不知道,
你需要处理断线后的续传问题.
你需要处理断线后的续传问题.
#2
if (fupUrl.PostedFile.ContentLength > 1024000)
{
fileOk = false;
Helper.CommonTools.AlertInfo("上传的作品大小不能超过3M!", "Upload.aspx");
return;
}
{
fileOk = false;
Helper.CommonTools.AlertInfo("上传的作品大小不能超过3M!", "Upload.aspx");
return;
}
#3
考虑用其他的吧!比如Flex,Ocx什么的好点吧?
#4
我现在的要求就是要处理大文件的上传问题,小于1G的都没什么用,而且怎么处理超过1G的断点后续上传问题
#5
路过学习
#6
system.web> </system.web>之间
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="21000" executionTimeout="300" />
maxRequestLength:设置上传文件的最大值,单位:KB。(默认是4096KB,即4M)
executionTimeout:设置超时时间,单位:秒。(默认是90秒)
用HttpWorkerRequest,GetPreloadedEntityBody 和 ReadEntityBody方法从IIS为ASP.NET建立的pipe里分块读取数据
http://topic.csdn.net/u/20091029/09/e5dc6f96-f1fb-4b61-b68d-546622b4b3e3.html
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="21000" executionTimeout="300" />
maxRequestLength:设置上传文件的最大值,单位:KB。(默认是4096KB,即4M)
executionTimeout:设置超时时间,单位:秒。(默认是90秒)
用HttpWorkerRequest,GetPreloadedEntityBody 和 ReadEntityBody方法从IIS为ASP.NET建立的pipe里分块读取数据
http://topic.csdn.net/u/20091029/09/e5dc6f96-f1fb-4b61-b68d-546622b4b3e3.html
#7
你写个函数 用线程分段上传
一下一下上传 不然会卡死的 太大的不行
貌似现在又大文件上传的控件
自己写一个比较好
一下一下上传 不然会卡死的 太大的不行
貌似现在又大文件上传的控件
自己写一个比较好
#8
Setting up Web.config to allow uploading of large files by ASP .NET applications
This article shows how to setup Web.config to allow uploading of files larger than 4 MB by ASP.NET applications.
Multiple File Upload With Progress Bar Using Flash and ASP.NET
How to use Flash to upload multiple files in a medium-trust hosting environment
This article shows how to setup Web.config to allow uploading of files larger than 4 MB by ASP.NET applications.
Multiple File Upload With Progress Bar Using Flash and ASP.NET
How to use Flash to upload multiple files in a medium-trust hosting environment
#9
少不了要支持断点续传功能!
#10
ASP.Net file post direct to disk with upload file progress support
This module gives developers a way to intercept multi-part form posts in ASP.Net and store the data directly to disk without going direct to memory. It also provides a way to extract the file progress from an external window. Written in C# for backend, and Javascript / Atlas for the progress bar.
Introduction
ASP.NET is a very nice and fast way to program small to enterprise level websites fast and efficiently. Most controls are perfect for any web development needed however the FileUpload control really has some short comings. Back when I used .net 1.1, I did some testing to see how the control worked and handled large files and was very unpleased.
I tried to upload a huge 1 or 2 gig file. I found myself with a problem where my web page would error, and the memory was never released. I left it at that, and did not mess with it anymore. I though for sure that the 2.0 framework would have fixed that problem but it appears that we were not that lucky (at least not that I could find).
Anyhow the project I was working on requires that I have control of what my users do. You never know when someone is going to try and upload some huge file on purpose or accident.
This module gives developers a way to intercept multi-part form posts in ASP.Net and store the data directly to disk without going direct to memory. It also provides a way to extract the file progress from an external window. Written in C# for backend, and Javascript / Atlas for the progress bar.
Introduction
ASP.NET is a very nice and fast way to program small to enterprise level websites fast and efficiently. Most controls are perfect for any web development needed however the FileUpload control really has some short comings. Back when I used .net 1.1, I did some testing to see how the control worked and handled large files and was very unpleased.
I tried to upload a huge 1 or 2 gig file. I found myself with a problem where my web page would error, and the memory was never released. I left it at that, and did not mess with it anymore. I though for sure that the 2.0 framework would have fixed that problem but it appears that we were not that lucky (at least not that I could find).
Anyhow the project I was working on requires that I have control of what my users do. You never know when someone is going to try and upload some huge file on purpose or accident.
#11
楼上的太强了,看不懂英文。。。。。
#12
帮顶。
#13
呵呵.Up
#14
关注
#15
继点续传没做过,但首先还得解决上传进度的问题吧,我关注
#16
这个东西 我改成了中文的
但是并不能解决 楼主的 上传 1G 的要求
#17
关注。。
#18
http://download.csdn.net/source/675091
LZ 去看看。。。。我没试!!!
好用,记得 发表下。。。
LZ 去看看。。。。我没试!!!
好用,记得 发表下。。。
#19
Mark一下,回头再看
#20
小关注一下
#21
web 上 上传那么大 干什么啊
#22
这个仅仅是一个设置而已
#23
10楼贴的那个类很强大
#24
写这个要支持多用户上传文件而且文件的基本都是大于1G的,虽然在ASP.NET里面可以设置文件上传的大小,不过好像不能达到我的要求,希望高手来解决下
#25
设置只是第一步,第二步用哪个文件上传类试试
#26
关注中
#27
标记一下,等神人出现
#28
1G,怎么会要上传这么大的文件?做FTP吧
#29
我有activex文件上传的控件
#30
支持大文件上传,断点续传
#31
断点续传呗。
把文件分割,用线程分块一段一段的传吧
把文件分割,用线程分块一段一段的传吧
#32
还是分割后上传吧
#33
路过,学习
没有试过这样大的文件上传
没有试过这样大的文件上传
#34
分割上传
#35
路过,学习
#36
mark up
#37
mark
#38
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Text;
using System.Web;
using System.Reflection;
namespace myHttpModule
{
/// <summary>
/// HttpUploadModule 的摘要说明。
/// </summary>
public class HttpUploadModule: IHttpModule
{
public HttpUploadModule()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(this.Application_BeginRequest);
application.EndRequest += new EventHandler(this.Application_EndRequest);
application.Error += new EventHandler(this.Application_Error);
}
public void Dispose()
{
}
private void Application_BeginRequest(Object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
// 如果是文件上传
if (IsUploadRequest(app.Request))
{
// 返回 HTTP 请求正文已被读取的部分。
HttpWorkerRequest request = GetWorkerRequest(app.Context);
Encoding encoding = app.Context.Request.ContentEncoding;
int bytesRead = 0; // 已读数据大小
int read; // 当前读取的块的大小
int count = 8192; // 分块大小
byte[] buffer; // 保存所有上传的数据
byte[] tempBuff = null;
if (request != null)
{
tempBuff = request.GetPreloadedEntityBody();
}
if (tempBuff != null)
{
// 获取上传大小
//
long length = long.Parse(request.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength));
buffer = new byte[length];
count = tempBuff.Length; // 分块大小
// 将已上传数据复制过去
//
Buffer.BlockCopy(tempBuff, 0, buffer, bytesRead, count);
// 开始记录已上传大小
//
bytesRead = tempBuff.Length;
// 循环分块读取,直到所有数据读取结束
//
while (request.IsClientConnected() &&
!request.IsEntireEntityBodyIsPreloaded() &&
bytesRead < length
)
{
// 如果最后一块大小小于分块大小,则重新分块
//
if (bytesRead + count > length)
{
count = (int)(length - bytesRead);
tempBuff = new byte[count];
}
// 分块读取
//
read = request.ReadEntityBody(tempBuff, count);
// 复制已读数据块
//
Buffer.BlockCopy(tempBuff, 0, buffer, bytesRead, read);
// 记录已上传大小
//
bytesRead += read;
}
if (
request.IsClientConnected() &&
!request.IsEntireEntityBodyIsPreloaded()
)
{
// 传入已上传完的数据
//
InjectTextParts(request, buffer);
// 表示上传已结束
}
}
}
}
/// <summary>
/// 结束请求后移除进度信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Application_EndRequest(Object sender, EventArgs e)
{
}
/// <summary>
/// 如果出错了设置进度信息中状态为“Error”
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Application_Error(Object sender, EventArgs e)
{
}
HttpWorkerRequest GetWorkerRequest(HttpContext context)
{
IServiceProvider provider = (IServiceProvider)HttpContext.Current;
return (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
}
/// <summary>
/// 传入已上传完的数据
/// </summary>
/// <param name="request"></param>
/// <param name="textParts"></param>
void InjectTextParts(HttpWorkerRequest request, byte[] textParts)
{
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic;
Type type = request.GetType();
while ((type != null) && (type.FullName != "System.Web.Hosting.ISAPIWorkerRequest"))
{
type = type.BaseType;
}
if (type != null)
{
type.GetField("_contentAvailLength", bindingFlags).SetValue(request, textParts.Length);
type.GetField("_contentTotalLength", bindingFlags).SetValue(request, textParts.Length);
type.GetField("_preloadedContent", bindingFlags).SetValue(request, textParts);
type.GetField("_preloadedContentRead", bindingFlags).SetValue(request, true);
}
}
/// <summary>
/// 是否为附件上传
/// 判断的根据是ContentType中有无multipart/form-data
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
bool IsUploadRequest(HttpRequest request)
{
return request.ContentType.ToLower()=="multipart/form-data";
}
}
}
需要在web.config中加入
<httpRuntime executionTimeout="600" maxRequestLength="1048576"/>
<httpModules>
<add name="HttpUploadModule" type="myHttpModule" />
</httpModules>
#39
呵呵,向这样的要求,要买收费的控件才行了。
以前试用过几个,还算不错。
以前试用过几个,还算不错。
#40
一般来说asp.net里只能传大约4mb的东西,但是实际需求下,可以采用很多方式比如flash,好像有个免费的flash可以上传的,lz搜索一下应该可以找到,再不行留个mail我好像有个
#41
需要使用第三方控件,有免费的
#42
通过网页来上传这么大的文件是不可取的,可以专门做个上传工具,或者上传控件,flash,active控件啥的。不过我没搞过~
#43
只能说这样的需求很有变态
#44
slickupload.
#45
mtom协议支持大文件分小块传输
#46
这个是什么控件啊?能告诉一下吗?
#47
http://www.evget.com/zh-CN/FeaturedArticle/Default.aspx?id=1
联系方式:qq 228184703
联系方式:qq 228184703
#48
用NeatUpload上传控件,免费的!上传1G以上的文件没有问题,我曾经做过!但好像不支持断点续传!
#49
#50
我就纳闷了 谁这么有劲啊 老顶 09年的帖子