private Boolean SaveImages()
{
///'遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files;
/// '状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append("上传的文件分别是:
");
try
{
for (int iFile = 0; iFile < files.Count; iFile++)
{
///'检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
string docPath = "~/ProjectDoc/" + this.fudDoc.FileName.ToString().Trim() + "";
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "
");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "
");
strMsg.Append("上传文件的文件名:" + fileName + "
");
strMsg.Append("上传文件的扩展名:" + fileExtension + "
");
///'可根据扩展名字的不同保存到不同的文件夹
///注意:可能要修改你的文件夹的匿名写入权限。
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("~/ProjectDoc/") + fileName);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch (System.Exception Ex)
{
strStatus.Text = Ex.Message;
return false;
}
}
这个写在pageload中
if (this.IsPostBack)
{
this.SaveImages();
}
上传东西是不用连数据库的,怎么不写虚拟路径呢?