ΪʲôִֻÐÐelseÓï¾ä£¿
³ÌÐò´úÂ룺
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class FileUpload : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { bool filesValib = false; if (this.FileUpload1.HasFile) { string fileExtension = (this.FileUpload1.FileName).ToLower(); string[] restricExtension = { "gif", "jpg", "bmp", "png" }; for (int i = 0; i < restricExtension.Length; i++) { if (fileExtension == restricExtension[i]) { filesValib = true; } } if (filesValib == true) { try { this.Image1.ImageUrl = "../../WebSite7/Image/password.gif"; this.FileUpload1.SaveAs(Server.MapPath("~/images/") + FileUpload1.FileName); this.Label1.Text = "ÎļþÉÏ´«³É¹¦"; this.Label1.Text += "<br/>"; this.Label1.Text += "<li>" + "Ô´Îļþ·¾¶£º" + this.FileUpload1.PostedFile.FileName; this.Label1.Text += "<br/>"; this.Label1.Text += "<li>" + "Îļþ´óС£º" + this.FileUpload1.PostedFile.ContentLength + "×Ö½Ú"; this.Label1.Text += "<br/>"; this.Label1.Text += "<li>" + "ÎļþÀàÐÍ:" + this.FileUpload1.PostedFile.ContentType; } catch { this.Label1.Text = "ÎļþÉÏ´«²»³É¹¦£¡"; } finally { } } else { this.Label1.Text = "Ö»Äܹ»ÉÏ´«ºó׺ÃûΪjpg, gif, png, bmpµÄÎļþ"; } } } }
Ñ¡ÖÐͼƬ¸ñʽµÄµÄÎļþµã»÷ÉÏ´« »¹ÊÇÖ±½ÓÌøµ½elseÓï¾ä Çó½âÊÍ