|
|
aspx 中轻松实现文件上传 |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
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

|
|
相关文章:相关软件: |
|