protected BXFile SaveFile(string type) { BXFile fImage = null; FileUpload fu; if ("detail".Equals(type, StringComparison.InvariantCultureIgnoreCase)) fu = DetailImg.Upload; else fu = Img.Upload; if (fu.HasFile) { fImage = new BXFile(fu.PostedFile, "iblock", "iblock", null); BXFileValidationResult fResult = fImage.ValidateAsImage(0, 0, 0); if (fResult != BXFileValidationResult.Valid) { string fError = ""; if ((fResult & BXFileValidationResult.InvalidContentType) == BXFileValidationResult.InvalidContentType) fError += GetMessage("Error.InvalidType"); if ((fResult & BXFileValidationResult.InvalidExtension) == BXFileValidationResult.InvalidExtension) { if (!String.IsNullOrEmpty(fError)) fError += ", "; fError += GetMessage("Error.Invalid.Extension"); } if ((fResult & BXFileValidationResult.InvalidImage) == BXFileValidationResult.InvalidImage) { if (!String.IsNullOrEmpty(fError)) fError += ", "; fError += GetMessage("Error.InvalidImage"); } throw new Exception(fError); } fImage.DemandFileUpload(); fImage.Save(); } return fImage; }
protected BXFile SaveFile(HttpPostedFile postedFile) { BXFile image = new BXFile(postedFile, "iblock", "iblock", null); BXFileValidationResult fResult = image.ValidateAsImage(0, 0, 0); if (fResult != BXFileValidationResult.Valid) { string fError = ""; if ((fResult & BXFileValidationResult.InvalidContentType) == BXFileValidationResult.InvalidContentType) fError += GetMessageRaw("Error.InvalidType"); if ((fResult & BXFileValidationResult.InvalidExtension) == BXFileValidationResult.InvalidExtension) { if (!String.IsNullOrEmpty(fError)) fError += ", "; fError += GetMessageRaw("Error.Inavlid.extension"); } if ((fResult & BXFileValidationResult.InvalidImage) == BXFileValidationResult.InvalidImage) { if (!String.IsNullOrEmpty(fError)) fError += ", "; fError += GetMessageRaw("Error.InvalidImage"); } throw new FormatException(fError); } image.DemandFileUpload(); image.Save(); return image; }
protected BXFile SaveFile(bitrix_ui_AdminImageField adminImageField, int currentImageId) { if (adminImageField == null) return null; BXFile image = null; FileUpload fileUpload = adminImageField.Upload; if (adminImageField.Upload.HasFile) { image = new BXFile(fileUpload.PostedFile, "iblock", "iblock", adminImageField.Description); BXFileValidationResult result = image.ValidateAsImage(0, 0, 0); if (result != BXFileValidationResult.Valid) { string errorMessage = ""; if ((result & BXFileValidationResult.InvalidContentType) == BXFileValidationResult.InvalidContentType) errorMessage += GetMessageRaw("InvalidType"); if ((result & BXFileValidationResult.InvalidExtension) == BXFileValidationResult.InvalidExtension) { if (!String.IsNullOrEmpty(errorMessage)) errorMessage += ", "; errorMessage += GetMessageRaw("InvalidExtension"); } if ((result & BXFileValidationResult.InvalidImage) == BXFileValidationResult.InvalidImage) { if (!String.IsNullOrEmpty(errorMessage)) errorMessage += ", "; errorMessage += GetMessageRaw("InvalidImage"); } throw new Exception(String.Format(GetMessageRaw("Error.InvalidImage"), errorMessage)); } image.DemandFileUpload(); image.Save(); return image; } else if (currentImageId > 0 && (image = BXFile.GetById(currentImageId)) != null) { image.Description = adminImageField.Description; image.Save(); } return null; }
protected BXFile SaveFile() { BXFile fImage = null; if (Img.Upload.HasFile) { fImage = new BXFile(Img.Upload.PostedFile, "iblock", "iblock", null); BXFileValidationResult fResult = fImage.ValidateAsImage(0, 0, 0); if (fResult != BXFileValidationResult.Valid) { string fError = ""; if ((fResult & BXFileValidationResult.InvalidContentType) == BXFileValidationResult.InvalidContentType) fError += GetMessage("Error.InvalidType"); if ((fResult & BXFileValidationResult.InvalidExtension) == BXFileValidationResult.InvalidExtension) { if (!String.IsNullOrEmpty(fError)) fError += ", "; fError += GetMessage("Error.InvalidExtension"); } if ((fResult & BXFileValidationResult.InvalidImage) == BXFileValidationResult.InvalidImage) { if (!String.IsNullOrEmpty(fError)) fError += ", "; fError += GetMessage("Error.InvalidImage"); } throw new Exception(fError); } fImage.DemandFileUpload(); fImage.Save(); } return fImage; }