protected void Button4_Click(object sender, EventArgs e)
{
string fullname = this.FileUpload4.PostedFile.FileName;
string filename = fullname.Substring(fullname.LastIndexOf("//") + 1);
string type = fullname.Substring(fullname.LastIndexOf(".")+1);
if (type == "jpg" || type == "gif" || type == "bmp")
{
this.FileUpload4.PostedFile.SaveAs(Server.MapPath("Upload") + "//" + filename);
}
else
{
Response.Write("<script language='java-script'>alert('你上传的文件格式不正确!')</script>");
}
}
{
string fullname = this.FileUpload4.PostedFile.FileName;
string filename = fullname.Substring(fullname.LastIndexOf("//") + 1);
string type = fullname.Substring(fullname.LastIndexOf(".")+1);
if (type == "jpg" || type == "gif" || type == "bmp")
{
this.FileUpload4.PostedFile.SaveAs(Server.MapPath("Upload") + "//" + filename);
}
else
{
Response.Write("<script language='java-script'>alert('你上传的文件格式不正确!')</script>");
}
}
说明:FileUpload为.NET中提供的控件;