应该是这样!
string fullname = this.File1.PostedFile.FileName;//取出上传文件的全部路径string filename = fullname.Substring(fullname.LastIndexOf("\\")+1);//截取最后一层目录下的文件名
filename = System.DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "");//给文件以当前日期时间重命名文件
string type = fullname.Substring(fullname.LastIndexOf(".") + 1);//截取文件的后缀名
filename = System.DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") +"."+ type;
if (type == "jpg" || type == "gif" || type == "bmp")//判断上传文件的格式
{
this.File1.PostedFile.SaveAs(Server.MapPath("uploads") + "\\" + filename);
this.Image1.ImageUrl = "uploads/" + filename;
this.TextBox1.Text = "uploads/"+filename;
}
else
{
Response.Write("<script language=javascript>alert('你选择的图片格式不正确!');</script>");
}