Rumah > Artikel > pembangunan bahagian belakang > asp.net fileupload 实现上传
protected void Button1_Click(object sender, EventArgs e) { string filename = this.DropDownList1.SelectedValue;//最终命名 if (this.FileUpload1.PostedFile != null) { string baseFilename = this.FileUpload1.PostedFile.FileName;//获取上传文件文件名 int i = baseFilename.LastIndexOf("."); string ext = baseFilename.Substring(i);//获取文件的扩展名 string savePath = Server.MapPath("~/pic/"); if (!System.IO.Directory.Exists(savePath)) { System.IO.Directory.CreateDirectory(savePath ); } savePath = savePath + "\\" + filename+ext; //Response.Write(ext ); if (!ext.Equals(".jpg") && !ext.Equals(".jpeg") && !ext.Equals(".bmp") && !ext.Equals(".gif") && !ext.Equals(".png")) { Response.Write("上传文件格式不正确!<a href="\" href="\""upload.aspx\">重新上传</a>"); Response.End(); } FileUpload1.PostedFile.SaveAs( savePath ); } }
更多asp.net fileupload 实现上传相关文章请关注PHP中文网!