//上传图片
if (this.fudFilePath.HasFile)//检查是否有文件
{
string fullFileName = this.fudFilePath.PostedFile.FileName;//文件路径名
string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);//图片名称
string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1);//图片格式
if (type == "jpg" || type == "JPG" || type == "gif" || type == "GIF" || type == "jpeg" || type == "JPEG")//判断是否为图片类型
{
string pat = HttpContext.Current.Request.MapPath("~/image/Picture/");//获取上传文件的网站目录路径
this.fudFilePath.SaveAs(pat + fileName);//存储文件到磁盘
this.imgFace.ImageUrl = "~/image/Picture/" + fileName; //显示图片
}
else
{
Response.Write("");
}
}
try
{
Picture p = new Picture();
p.Title = this.txtTitle.Value.Trim();//标题
p.PictureCategories = this.txtFactory.Value.Trim();//类别
p.UserName = this.txtUserName.Value.Trim();//上传人
p.PictureUpload = Path.GetFileName(this.fudFilePath.PostedFile.FileName);//图片上传
p.Description = this.txtDescription.Value.Trim();//描述
PictureBLL pb = new PictureBLL();
pb.Insert(p);
}
catch
{
Response.Write("");
}
我写的是在同一个页面显示,希望看了之后对你有帮助