ASP.NET文件上载问题 [英] ASP.NET File Upload problem

查看:68
本文介绍了ASP.NET文件上载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿。


我正在尝试使用ASP.NET进行文件上传的可能性。

我遇到了一个问题:(


我可以上传小文件,但是如果我尝试更大的文件它就行不通......


任何可以帮助我的人?​​


谢谢。

K.

private void btnUpload_Click(object sender,System.EventArgs e)

{

string strBaseLocation = Server.MapPath(&.;。/ files");


if(txtUploadFile.Value == string.Empty)

{

lblInfo.Text =" Gelieve een bestand te selecteren。" ;;

return;

}


string fileName = GetFileName(txtUploadFile.Value);

string fileTarget = strBaseLocation +" \\" + fileName;

if(null!= txtUploadFile.PostedFile)

{

试试

{

/ / read / write buffer

const int BUFFER_SIZE = 255;

Byte [] Buffer = new Byte [BUFFER_SIZE];

lblInfo.Text =" Uploading File:" + fileName;


//传入的外部文件流

Stream theStream = txtUploadFile.PostedFile.InputStream;


//本地文件流

FileStream fs = new FileStream(fileTarget,FileMode.CreateNew,

FileAccess.Write);


//本地文件流上的本地二进制写入器

BinaryWriter bw = new BinaryWriter(fs);

//读/写循环

while( theStream.Read(Buffer,0,BUFFER_SIZE)!= 0)

{

bw.Write(Buffer,0,BUFFER_SIZE);

}


//关闭溪流

bw.Close();

fs.Close();

theStream.Close();

lblInfo.Text ="上传完成。;


//重新加载目录列表

FindAndDisplayFiles();

}

catch(例外情况)

{

lblInfo。 Text =" Fout bij het uploaden。< br>" + ex.Message;

}

}

}

Hey.

I was experimenting with file uploading possibility using ASP.NET.
I ran into a problem :(

I can upload small files, but if I try a bigger file it doesn''t work...

Anyone who can help me please ?

Thanks.
K.
private void btnUpload_Click(object sender, System.EventArgs e)
{
string strBaseLocation = Server.MapPath( "./files" );

if ( txtUploadFile.Value == string.Empty )
{
lblInfo.Text = "Gelieve een bestand te selecteren.";
return;
}

string fileName = GetFileName( txtUploadFile.Value );
string fileTarget = strBaseLocation + "\\" + fileName;

if (null != txtUploadFile.PostedFile)
{
try
{
//read/write buffer
const int BUFFER_SIZE = 255;
Byte[] Buffer = new Byte[BUFFER_SIZE];
lblInfo.Text = "Uploading File: " + fileName;

//incoming external file stream
Stream theStream = txtUploadFile.PostedFile.InputStream;

//local file stream
FileStream fs = new FileStream(fileTarget, FileMode.CreateNew,
FileAccess.Write);

//local binary writer on local file stream
BinaryWriter bw = new BinaryWriter(fs);
// read/write loop
while( theStream.Read(Buffer, 0, BUFFER_SIZE) != 0 )
{
bw.Write(Buffer, 0, BUFFER_SIZE);
}

//Close the streams
bw.Close();
fs.Close();
theStream.Close();
lblInfo.Text = "Upload finished.";

//reload directory listing
FindAndDisplayFiles();
}
catch(Exception ex)
{
lblInfo.Text = "Fout bij het uploaden.<br>" + ex.Message;
}
}
}

推荐答案

k,已经发现httpRunTime默认为最大4000 kb ...

< configuration>

< system.web>

< httpRuntime maxRequestLength =" 4000"

useFullyQualifiedRedirectUrl =" true"

executionTimeout =" 45"

versionHeader =" 1.1.4128" />

< /system.web>

< / configuration>


如何更改?


谢谢。

K.



" Asshen Shugar < VA ******** @ hotmail.com>在消息中写道

新闻:6H ********************* @ phobos.telenet-ops.be ...
k, already found that httpRunTime defaults to max 4000 kb...

<configuration>
<system.web>
<httpRuntime maxRequestLength="4000"
useFullyQualifiedRedirectUrl="true"
executionTimeout="45"
versionHeader="1.1.4128"/>
</system.web>
</configuration>

How do I change it ?

Thank you.
K.


"Asshen Shugar" <va********@hotmail.com> wrote in message
news:6H*********************@phobos.telenet-ops.be...
嘿。

我正在尝试使用ASP.NET进行文件上传的可能性。
我遇到了一个问题:(

我可以上传小文件,但如果我尝试更大的档案,它就不起作用......

任何可以帮助我的人都好吗?

谢谢。
K.

private void btnUpload_Click(object sender,System.EventArgs e)
{str / String string>&。 if(txtUploadFile.Value == string.Empty)
{
lblInfo.Text =" Gelieve een bestand te selecteren。" ;;
return;
}

string fileName = GetFileName(txtUploadFile.Value);
string fileTarget = strBaseLocation +" \\" + fileName;

if(null!= txtUploadFile.PostedFile )
{
尝试
//读/写缓冲区
const int BUFFER_SIZE = 255;
Byte [] Buffe r =新字节[BUFFER_SIZE];
lblInfo.Text ="上传文件:" + fileName;

//传入外部文件流
流theStream = txtUploadFile.PostedFile.InputStream;

//本地文件流
FileStream fs =新的FileStream(fileTarget,FileMode.CreateNew,
FileAccess.Write);

//本地文件流上的本地二进制写程序
BinaryWriter bw = new BinaryWriter(fs);

//读/写循环
while(theStream.Read(Buffer,0,BUFFER_SIZE)!= 0)
{
bw.Write(Buffer,0,BUFFER_SIZE) );
}
//关闭溪流
bw.Close();
fs.Close();
theStream.Close();

lblInfo.Text ="上传完成。;

//重新加载目录列表
FindAndDisplayFiles();
}
catch(Exception ex)
{
lblInfo.Text =" Fout bij het uploaden。< br>" + ex.Message;
}
}
Hey.

I was experimenting with file uploading possibility using ASP.NET.
I ran into a problem :(

I can upload small files, but if I try a bigger file it doesn''t work...

Anyone who can help me please ?

Thanks.
K.
private void btnUpload_Click(object sender, System.EventArgs e)
{
string strBaseLocation = Server.MapPath( "./files" );

if ( txtUploadFile.Value == string.Empty )
{
lblInfo.Text = "Gelieve een bestand te selecteren.";
return;
}

string fileName = GetFileName( txtUploadFile.Value );
string fileTarget = strBaseLocation + "\\" + fileName;

if (null != txtUploadFile.PostedFile)
{
try
{
//read/write buffer
const int BUFFER_SIZE = 255;
Byte[] Buffer = new Byte[BUFFER_SIZE];
lblInfo.Text = "Uploading File: " + fileName;

//incoming external file stream
Stream theStream = txtUploadFile.PostedFile.InputStream;

//local file stream
FileStream fs = new FileStream(fileTarget, FileMode.CreateNew,
FileAccess.Write);

//local binary writer on local file stream
BinaryWriter bw = new BinaryWriter(fs);
// read/write loop
while( theStream.Read(Buffer, 0, BUFFER_SIZE) != 0 )
{
bw.Write(Buffer, 0, BUFFER_SIZE);
}

//Close the streams
bw.Close();
fs.Close();
theStream.Close();
lblInfo.Text = "Upload finished.";

//reload directory listing
FindAndDisplayFiles();
}
catch(Exception ex)
{
lblInfo.Text = "Fout bij het uploaden.<br>" + ex.Message;
}
}
}



Asshen Shugar写道:
Asshen Shugar wrote:
< httpRuntime maxRequestLength =" 4000"
如何更改?
<httpRuntime maxRequestLength="4000"
How do I change it ?



你,呃......改变它。你试过的时候发生了什么?


You, uhh... change it. What happened when you tried?


我可以上传最大大小为4000 kB的文件。

这就是$.
我尝试添加< httpRuntime>我的项目的Web.config中的节点,但是

不起作用(猜测machine.config比

应用程序级别有更大的权限吗?)。 />

所以我看到的唯一解决方案是更改machine.config文件?

这是正确的吗?


K


" jasonkester" < JA ********* @ gmail.com>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...
I can upload files of a maximum size of 4000 kB.
That''s the default maximum size specified in Machine.config.

I tried to add the <httpRuntime> node in the Web.config of my project, but
that doesn''t work (guess machine.config has greater permission than on
application level ?).

So the only solution I see is changing the machine.config file ?
Is that correct ?

K

"jasonkester" <ja*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Asshen Shugar写道:
Asshen Shugar wrote:
< httpRuntime maxRequestLength =" 4000"
如何更改?
<httpRuntime maxRequestLength="4000"
How do I change it ?



你,呃... 更改。你试过的时候发生了什么?


You, uhh... change it. What happened when you tried?



这篇关于ASP.NET文件上载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆