/// <summary> /// 上传图片 /// </summary> /// <param name="file"></param> /// <returns></returns> public string UpImg(FileUpload file) { string filename; string filepath; string fileext; filename = file.PostedFile.FileName; filename = Path.GetFileName(filename); fileext = Path.GetExtension(filename);//获得文件扩展名 string NewFileName = string.Empty; if (file.PostedFile.FileName != "") { if (fileext == ".bmp" || fileext == ".jpg" || fileext == ".JPG" || fileext == ".GIF" || fileext == ".gif" || fileext == ".png") { NewFileName = string.Format("{0}{1}", DateTime.Now.ToString("yyyymmddhhmmss"), fileext); filepath = "~/UploadFiles/" + NewFileName; file.PostedFile.SaveAs(Server.MapPath(filepath)); } } return NewFileName; }