protected override void ExtractValues(IOrderedDictionary dictionary) { _uploadAttribute = MetadataAttributes.GetAttribute<Entities.UploadAttribute>(); if (_uploadAttribute == null) { // no attribute thrw an error throw new InvalidOperationException("FileUpload must have valid uploadAttribute applied"); } // make sure file is valid if (!FileUpload1.HasFile || !Page.IsValid) return; // make sure we have the folder to upload the file to var uploadFolder = Server.MapPath(VirtualPathUtility.AppendTrailingSlash(_uploadAttribute.UploadFolder)); if (!Directory.Exists(uploadFolder)) Directory.CreateDirectory(uploadFolder); //resize the imge var file = FileUpload1.PostedFile; var bitmap = new Bitmap(file.InputStream); var avatarBitmap = new Bitmap(bitmap, _uploadAttribute.Width, _uploadAttribute.Height); var graphic = Graphics.FromImage(avatarBitmap); graphic.SmoothingMode = SmoothingMode.AntiAlias; graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; // Draw the new graphic based on the resized bitmap graphic.DrawImage(avatarBitmap, 0, 0, _uploadAttribute.Width, _uploadAttribute.Height); var extention = Path.GetExtension(file.FileName); var filename = Guid.NewGuid() + extention; var path = uploadFolder+filename; avatarBitmap.Save(path); bitmap.Dispose(); avatarBitmap.Dispose(); graphic.Dispose(); // upload img // update the field with the filename dictionary[Column.Name] = ConvertEditedValue(filename); }
protected void Page_Load(object sender, EventArgs e) { CustomValidator1.Text = "*"; SetUpValidator(CustomValidator1); // get attributes _uploadAttribute = MetadataAttributes.GetAttribute<Entities.UploadAttribute>(); if (_uploadAttribute == null) { // no attribute thrw an error throw new InvalidOperationException("FileUpload must have valid uploadAttribute applied"); } }