① .net fileupload控制項上傳大文件(至少50M以上)
注意修胡猛改笑做信了上傳文件的大小,就一定要修改超時的時間
在web.config中的<system.web></system.web>內加入如下代碼:
<httpRuntime executionTimeout="600" maxRequestLength="951200"
useFullyQualifiedRedirectUrl="true" minFreeThreads="8"
minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true"/碰輪>
② .net 獲取以上傳文件大小 並輸出
用FileUpload上傳……給它起個ID。然後獲取上傳文件的大小this.FileUpload1.PostedFile.ContentLength
③ asp.net怎樣上傳超過2GB的大文件
用upload第三方的控制項,還支持多文件批量上傳,上傳大小不限制(可以自己設置).
網上有這個控制項,很好用。
④ .net中,怎樣設置文件上傳的大小。
實際例子(已上傳圖片為例)
protected void UpImg_Click(object sender, EventArgs e)//上傳圖片
{
if (FileUpload1.PostedFile.ContentLength < 500000)//100000為100K
{
string fileFullname = this.FileUpload1.FileName;
string dataName = DateTime.Now.ToString("yyyyMMddhhmmss");
string fileName = fileFullname.Substring(fileFullname.LastIndexOf("\\") + 1);
string type = fileFullname.Substring(fileFullname.LastIndexOf(".") + 1);
if (type == "bmp" || type == "jpg" || type == "gif" || type == "JPG" || type == "BMP" || type == "GIF")
{
this.FileUpload1.SaveAs(Server.MapPath("../upload") + "\\" + dataName + "." + type);
string ProImg = "upload/" + dataName + "." + type;
this.txtProImg.Text = "upload/" + dataName + "." + type;
}
else
{
Response.Write("<script language='javascript'>alert('支持格式:||gif|bmp|');</script>");
}
}
else
{
Response.Write("<script language='javascript'>alert('你的圖片已經超過500K的大小!');</script>");
}
}
web.config配置
web.config文件的內容大體如此:
<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
<sessionState mode="InProc" cookieless="false" timeout="20"/>
<httpRuntime maxRequestLength="47185920">
</httpRuntime>
</system.web>
</configuration>
注意在文件中的位置,
講解:
<sessionState mode="InProc" cookieless="false" timeout="20"/>
//cookieless="false",不使用cookies
//timeout="20",會話時間為20分鍾,單位是分鍾,這里可自行修改
<httpRuntime maxRequestLength="47185920">
//站點默認上傳的最大文件