在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
public partial class FileUpload : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btn_Save_onclick(object sender, EventArgs e) { Boolean fileOK = false; String path = Server.MapPath("~/Uploads/"); if (fu.HasFile) { String fileExtension = System.IO.Path.GetExtension(fu.FileName).ToLower(); String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" }; for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileOK = true; } } } if (fileOK) { try { fu.PostedFile.SaveAs(path + fu.FileName); } catch (Exception ex) { } } else { } } }
<body> <form > <div> <asp:FileUpload ID="fu" runat="Server" MaxRequestLength="" BackColor="#6699FF" Height="42px" Width="257px" /> <br /> <asp:Button Text="存储" ID="btn_Save" runat="server" OnClick="btn_Save_onclick" style="margin-left: 153px" /> </div> </form> </body>
|
请发表评论