aspx 中轻松实现文件上传

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

aspx 中轻松实现文件上传

在aspx中实现文件上传是非常容易的,如下代码:

private string upLoadFile(System.Web.UI.HtmlControls.HtmlInputFile tFile,string FilePath)

{

if(tFile.PostedFile.ContentLength>0 )

{

string strFileName = Path.GetFileName(tFile.PostedFile.FileName);

tFile.PostedFile.SaveAs(FilePath + strFileName) ;

return strFileName;

}else{

return "";

}

}

但是有一个问题,如果你的附件大小操作4m那么上传文件会报错,为什么会报错?原因是aspx默认的maxRequestLength 的大小为4096KB也就是4MB,我们需要在Web.config更改如下设置,当然具体的数值根据实际情况来定。

<system.web>

...

<httpRuntime

executionTimeout="300"

maxRequestLength="40960"

useFullyQualifiedRedirectUrl="false"

/>

...

</system.web>

executionTimeout 单位秒

maxRequestLength 单位KB

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航