(1)
String savePath = @"D:/";
if (this.FileUpload1.HasFile)
{
String filename;
filename = FileUpload1.FileName;
savePath += filename;
FileUpload1.SaveAs(savePath);
Page.Response.Write(FileUpload1.PostedFile.ContentType + FileUpload1.PostedFile.ContentLength);
}
(2)获取上传文件的类型,大小!
"客户端路径:" + FileUpload1.PostedFile.FileName + "<br>" +
"文件名:" + System.IO.Path.GetFileName(FileUpload1.FileName) + "<br>" +
"文件扩展名:" + System.IO.Path.GetExtension(FileUpload1.FileName) + "<br>" +
"文件大小:" + FileUpload1.PostedFile.ContentLength + " KB<br>" +
"文件MIME类型:" + FileUpload1.PostedFile.ContentType + "<br>" +
"保存路径:" + Server.MapPath("upload") + "//" + FileUpload1.FileName;
(3)如何解决上传文件的大小?
在ASP.NET 2.0中FileUpload默认上传文件最大为4M,可以在web.cofig中修改相关节点来更改这个默认值,相关节点如下:
程序代码
<system.web>
<httpRuntime maxRequestLength="40690" executionTimeout="6000" />
</system.web>
maxRequestLength表示可上传文件的最大值,executionTimeout表示ASP.NET关闭前允许发生的上载秒数