/// <summary> /// Updates this instance. /// </summary> public void Update() { if (!String.IsNullOrEmpty(hfFileUpMetaValueCtrlSessionUID.Value)) { // restore old SessionUid value FileUpMetaValueCtrl.SessionUid = new Guid(hfFileUpMetaValueCtrlSessionUID.Value); } if (RemoveFile.Checked) { MetaHelper.SetMetaFile(MetaField.Context, MetaObject, MetaField.Name, String.Empty, String.Empty, null); return; } if (FileUpMetaValueCtrl.Files != null && FileUpMetaValueCtrl.Files.Length > 0) { //string folderPath = ConfigurationManager.AppSettings["FolderPath"].ToString(); string localPath = Path.GetTempPath(); //Server.MapPath(folderPath); DirectoryInfo di = new DirectoryInfo(localPath); if (di != null) { FileStreamInfo[] fsi = FileUpMetaValueCtrl.Files; //Create byte Array with file length // use [0] index here, since we allow to load only 1 file Byte[] data = new Byte[fsi[0].Size]; Stream stream = TempFileStorage.Provider.GetStream(fsi[0].StreamUid); stream.Read(data, 0, Convert.ToInt32(fsi[0].Size)); MetaHelper.SetMetaFile(MetaField.Context, MetaObject, MetaField.Name, fsi[0].FileName, fsi[0].ContentTypeName, data); } } }
/// <summary> /// Updates this instance. /// </summary> public void Update() { if (RemovePicture.Checked) { MetaHelper.SetMetaFile(MetaField.Context, MetaObject, MetaField.Name, String.Empty, String.Empty, null); return; } byte[] data = null; if (MetaValueCtrl.PostedFile != null && MetaValueCtrl.PostedFile.ContentLength > 0) { //To create a PostedFile McHttpPostedFile File = MetaValueCtrl.PostedFile; if (File.ContentLength == 0) { return; } //if (!MetaField.ImageProperty.AutoResizeImage || File.ContentType.Contains("gif")) { //Create byte Array with file len data = new Byte[File.ContentLength]; //force the control to load data in array File.InputStream.Read(data, 0, File.ContentLength); } //else { //data = ImageGenerator.CreateImageThumbnail(File.InputStream, File.ContentType, MetaField.ImageProperty.ImageHeight, MetaField.ImageProperty.ImageWidth, MetaField.ImageProperty.StretchImage); } MetaHelper.SetMetaFile(MetaField.Context, MetaObject, MetaField.Name, File.FileName, File.ContentType, data); } }