在asp.net 2.0中,上傳文件時變的比較方便了,因為有了fileupload控件,使用十分簡單, 設置maxRequestLenth屬性,這里為11000KB,即11MB。 而對于多文件上傳,也很簡單,比如一個例子 for (int i = 0; i < uploadedFiles.Count; i++) try userPostedFile.SaveAs(filepath + "http://" + Label1.Text += "Location where saved: " + }
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,比如
<htt
string filepath = "d://luceneData//";
HttpFileCollection uploadedFiles = Request.Files;
{
HttpPostedFile userPostedFile = uploadedFiles[i];
{
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>";
System.IO.Path.GetFileName(userPostedFile.FileName));
filepath + "http://" +
System.IO.Path.GetFileName(userPostedFile.FileName) +
"<p>";
}
}
catch (Exception Ex)
{
Label1.Text += "Error: <br>" + Ex.Message;
}
}
http://www.49028c.com/jackyrong/archive/2006/09/26/514969.html
新聞熱點
疑難解答