protected void Button1_Click(object sender, EventArgs e)
{
string fullFileName= this.FileUpload1.PostedFile.FileName;//获取文件的全称 如:c://
string fullName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);//把全称进行截取到想要的那个文件名到服务器上
string type = fullFileName.Substring(fullFileName.LastIndexOf(".")+1);//获取图片的格式后面的那个后缀名
if (type == "jpg" || type == "gif")
{
this.FileUpload1.PostedFile.SaveAs(Server.MapPath("up") + "\\" + fullName);//把图片上传到服务器上up的目录上
// this.Image1.ImageUrl = "up/" + fullName;
this.Image1.ImageUrl = "up/"+fullName;
}
else
{
Response.Write("<script language='javascript'>alert('错了')</script>");
}
}
{
string fullFileName= this.FileUpload1.PostedFile.FileName;//获取文件的全称 如:c://
string fullName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);//把全称进行截取到想要的那个文件名到服务器上
string type = fullFileName.Substring(fullFileName.LastIndexOf(".")+1);//获取图片的格式后面的那个后缀名
if (type == "jpg" || type == "gif")
{
this.FileUpload1.PostedFile.SaveAs(Server.MapPath("up") + "\\" + fullName);//把图片上传到服务器上up的目录上
// this.Image1.ImageUrl = "up/" + fullName;
this.Image1.ImageUrl = "up/"+fullName;
}
else
{
Response.Write("<script language='javascript'>alert('错了')</script>");
}
}
看看路径
this.Image1.ImageUrl=Server.MapPath("up") + "\\" + fullName;(和保存路径一致)
this.Image1.ImageUrl=Server.MapPath("up") + "\\" + fullName;(和保存路径一致)这个还是不行?