asp.net 2.0的文件上傳(突破上傳限制4M)
更新時間:2009年06月05日 23:26:20 作者:
在asp.net 2.0中,因為有了fileupload控件,上傳文件十分簡單
復制代碼 代碼如下:
if (FileUpload1.HasFile)
try
{
FileUpload1.SaveAs("d:\\luceneData\\" + FileUpload1.FileName);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
else
{
Label1.Text = "You have not specified a file.";
}
還可以在web.config文件中,突破默認上傳限制的4MB,比如
<httpRuntime
executionTimeout="110"
maxRequestLength="11000"
requestLengthDiskThreshold="80"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="5000"
enableKernelOutputCache="true"
enableVersionHeader="true"
requireRootedSaveAsPath="true"
enable="true"
shutdownTimeout="90"
delayNotificationTimeout="5"
waitChangeNotification="0"
maxWaitChangeNotification="0"
enableHeaderChecking="true"
sendCacheControlHeader="true"
apartmentThreading="false" />
設置maxRequestLenth屬性,這里為11000KB,即11MB。
而對于多文件上傳,也很簡單,比如一個例子
string filepath = "d:\\luceneData\\";
HttpFileCollection uploadedFiles = Request.Files;
for (int i = 0; i < uploadedFiles.Count; i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];
try
{
if (userPostedFile.ContentLength > 0)
{
Label1.Text += "<u>File #" + (i + 1) +
"</u><br>";
Label1.Text += "File Content Type: " +
userPostedFile.ContentType + "<br>";
Label1.Text += "File Size: " +
userPostedFile.ContentLength + "kb<br>";
Label1.Text += "File Name: " +
userPostedFile.FileName + "<br>";
userPostedFile.SaveAs(filepath + "\\" +
System.IO.Path.GetFileName(userPostedFile.FileName));
Label1.Text += "Location where saved: " +
filepath + "\\" +
System.IO.Path.GetFileName(userPostedFile.FileName) +
"<p>";
}
}
catch (Exception Ex)
{
Label1.Text += "Error: <br>" + Ex.Message;
}
}
}
您可能感興趣的文章:
- 收藏的asp.net文件上傳類源碼
- Asp.net 文件上傳類(取得文件后綴名,保存文件,加入文字水印)
- asp.net 大文件上傳 之 改版了的SlickUpload.HttpUploadModule(Krystalware.SlickUpload.dll)
- asp.net slickupload 使用方法(文件上傳)
- asp.net 文件上傳與刷新與asp.net頁面與iframe之間的數據傳輸
- asp.net 模擬提交有文件上傳的表單(通過http模擬上傳文件)
- asp.net 多文件上傳,兼容IE6/7/8,提供完整代碼下載
- asp.net 簡便無刷新文件上傳系統
- asp.net(c#)開發(fā)中的文件上傳組件uploadify的使用方法(帶進度條)
- 用Fine Uploader+ASP.NET MVC實現ajax文件上傳[代碼示例]
- Asp.Net 無刷新文件上傳并顯示進度條的實現方法及思路
- ASP.NET MVC處理文件上傳的小例子
- asp.net 文件上傳實例匯總
- asp.net文件上傳示例分享
- asp.net fileupload控件上傳文件與多文件上傳
- ASP.NET實現的簡單易用文件上傳類
- ASP.NET對大文件上傳的解決方案
- asp.net批量多選文件上傳解決方案
- ASP.NET設計FTP文件上傳的解決方案
- asp.net文件上傳帶進度條實現案例(多種風格)
- asp.net文件上傳解決方案(圖片上傳、單文件上傳、多文件上傳、檢查文件類型)
相關文章
asp.net textbox javascript實現enter與ctrl+enter互換 文本框發(fā)送消息與換行(類似
今天與大家分享一下 asp.net textbox javascript實現enter與ctrl+enter互換 文本框發(fā)送消息與換行(類似于QQ),這個功能到底怎么實現?首先聲明以下幾點2012-01-01
asp.net實現上傳圖片時判斷圖片的模式GRB或CMYK的方法
這篇文章主要介紹了asp.net實現上傳圖片時判斷圖片的模式GRB或CMYK的方法,涉及asp.net針對圖片的讀取及屬性操作相關技巧,需要的朋友可以參考下2016-07-07

