System.IO.Stream iStream = null; // Buffer to read 10K bytes in chunk: byte[] buffer = new Byte[10000]; // Length of the file: int length; // Total bytes to read: long dataToRead; // Identify the file to download including its path. string filepath = "DownloadFileName"; // Identify the file name. string filename = System.IO.Path.GetFileName(filepath); try { // Open the file. iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read,System.IO.FileShare.Read); // Total bytes to read: dataToRead = iStream.Length; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); // Read the bytes. while (dataToRead > 0) { // Verify that the client is connected. if (Response.IsClientConnected) { // Read the data in buffer. length = iStream.Read(buffer, 0, 10000); // Write the data to the current output stream. Response.OutputStream.Write(buffer, 0, length); // Flush the data to the HTML output. Response.Flush(); buffer= new Byte[10000]; dataToRead = dataToRead - length; } else { //prevent infinite loop if user disconnects dataToRead = -1; } } } catch (Exception ex) { // Trap the error, if any. Response.Write("Error : " + ex.Message); } finally { if (iStream != null) { //Close the file. iStream.Close(); } }
找到windows\system32\inesrv\下的metabase.xml,
打开,找到ASPMaxRequestEntityAllowed 把他修改为需要的值,默认为204800,即200K
然后重启iis admin service服务
把它修改为51200000(50M)
我建议楼主用ftp传吧!
代码也有很多,我们上传大文件都用ftp的,不能用http
ASP.NET默认上传文件大小是4M,通过修改Machine.config文件可以提高上传文件大小...300M建议楼主换另一种上传文件方式,用HTTP可能会超时或客户端显示白页,长时间不响应等症状...
找到里面一个4092的修改
理论上传1G,局域网没什么问题的。
广域网上传300M也没什么问题,只是要等得久点,是很久很久!!想起来就好笑,我前段时间做了系统,里面就有个这种的上传,竟然还有客户哈戳戳的上传600多M的,他还很光荣的告诉我,他等了好久才传上去。
真是服了他了。
不过象这种大文件,建议用另一种方式,不要用http上传,因为不能续传,老火。
要不就做个ActiveX,用ftp的方法上传,既可续传又不怕文件大。限制性小
http://blog.joycode.com/saucer/archive/2004/03/16/16225.aspx
byte[] buffer = new Byte[10000]; // Length of the file:
int length; // Total bytes to read:
long dataToRead; // Identify the file to download including its path.
string filepath = "DownloadFileName"; // Identify the file name.
string filename = System.IO.Path.GetFileName(filepath); try
{
// Open the file.
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,
System.IO.FileAccess.Read,System.IO.FileShare.Read);
// Total bytes to read:
dataToRead = iStream.Length; Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); // Read the bytes.
while (dataToRead > 0)
{
// Verify that the client is connected.
if (Response.IsClientConnected)
{
// Read the data in buffer.
length = iStream.Read(buffer, 0, 10000); // Write the data to the current output stream.
Response.OutputStream.Write(buffer, 0, length); // Flush the data to the HTML output.
Response.Flush(); buffer= new Byte[10000];
dataToRead = dataToRead - length;
}
else
{
//prevent infinite loop if user disconnects
dataToRead = -1;
}
}
}
catch (Exception ex)
{
// Trap the error, if any.
Response.Write("Error : " + ex.Message);
}
finally
{
if (iStream != null)
{
//Close the file.
iStream.Close();
}
}
<httphander maxrequestlength=99999999999></httphander>
net支持最大8m
好像楼上的说ftp比较现实一些