string FuJianName = ""; string sl = ""; if (this.fileUploadImg.HasFile) { //全名 11aa.jpg string fullFileName = this.fileUploadImg.PostedFile.FileName; FuJianName = System.IO.Path.GetFileName(fullFileName); //文件名称 a.jpg //后缀 .jpg string exName = Path.GetExtension(fullFileName); if (exName.Trim().ToLower().ToString() == ".jpg" || exName.Trim().ToLower().ToString() == ".png" || exName.Trim().ToLower().ToString() == ".gif") { sl = "建档" + txtCName.Value.Trim().ToString() + exName; //自定义名称 string savePath = Server.MapPath("UPimg/NewATT/") + sl; this.fileUploadImg.PostedFile.SaveAs(savePath); // this.fileUploadImg.SaveAs(savePath); } else { Page.RegisterStartupScript("", "<script>f_alert2('warn','请只上传jpg、.gif、.png格式的图片!');</script>"); return; } }