protected void Button1_Click(object sender, EventArgs e) {
bool Files = false; //判断文件的类型是否符合要求
if(this .FileUpload1.HasFile) {
//获取删除文件的后缀
string fileSuffix = System.IO.Path.GetExtension(this .FileUpload1.FileName).ToLower();
string[] Suffix={".jpg",".bmp",".gif","pnd"}; //判断文件是否符合要求
for (int i = 0; i < Suffix.Length;i++) {
if (fileSuffix == Suffix[i]) { Files = true; } }
} //如果符合要求就上次,并显示信息
if (Files == true)
{
this.Image1.ImageUrl = "~/imager/" + FileUpload1.FileName;
this.FileUpload1.SaveAs(Server.MapPath("~/imager/") + FileUpload1.FileName);
} else {
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "");
}
}