protected override void ExtractValues(IOrderedDictionary dictionary) { dictionary[Column.Name] = ConvertEditedValue(TextBox1.Text); if (FileUpload1.Visible && FileUpload1.HasFile && Column.Name.ToLower().Contains("image")) { MediaModel mm = new MediaModel(); System.Drawing.Image newImage = (Bitmap)((new ImageConverter()).ConvertFrom(FileUpload1.FileBytes)); if (TextBox1.Text != "")//WE TRY TO DELETE HERE { try { bool deleted = UtilsConfig.ImageKeepFullURL? mm.DeleteImage(TextBox1.Text.Replace(UtilsConfig.AzureStorage_BaseURL(), "")): mm.DeleteImage(TextBox1.Text); } catch (Exception ex) { } } string newName = Guid.NewGuid().ToString("N").Substring(0, 10); string[] result = mm.Save(newName, UtilsConfig.Get(enumConfigKeys.Storage_Container), newImage); newName = result[1]; Image1.ImageUrl = result[1]; TextBox1.Text = result[0]; dictionary[Column.Name] = UtilsConfig.ImageKeepFullURL? result[1]: result[0]; } else if (Column.Name.ToLower().Contains("image")) { FileUpload1.Visible = true; Image1.Visible = true; Image1.ImageUrl = UtilsConfig.ImageKeepFullURL ? TextBox1.Text : UtilsConfig.AzureStorage_BaseURL() + TextBox1.Text; } else { Image1.Visible = false; FileUpload1.Visible = false; } }
protected void setImages(GridView GridView1) { if (!GridView1.EnableSortingAndPagingCallbacks) { return; } System.Collections.ObjectModel.ReadOnlyCollection <MetaColumn> cols = GridView1.GetMetaTable().Columns; bool conainsimages = (from cc in cols.ToList() where cc.Name.ToLower().Contains("image") select cc).FirstOrDefault() != null; if (!conainsimages) { return; } string baseurl = UtilsConfig.AzureStorage_BaseURL(); int row = -1; foreach (GridViewRow gv in GridView1.Rows) { row++; if (!gv.Visible) { continue; } TableCellCollection tbc = gv.Cells; int cellPosition = -1; foreach (TableCell ob in tbc) { cellPosition++; if (GridView1.HeaderRow.Cells[cellPosition].Controls.Count == 0) { continue; } object lb = (object)GridView1.HeaderRow.Cells[cellPosition].Controls[0]; if (lb == null || lb.GetType().BaseType != typeof(LinkButton)) { continue; } if (((LinkButton)lb).Text.ToLower().Contains("image") && !((LinkButton)lb).Text.ToLower().Contains("type")) { ControlCollection cl = ob.Controls; // object l = (object)cl[0]; // DynamicControl dn = (DynamicControl)l; DynamicControl dn = (DynamicControl)((object)cl[0]); Literal lt = (Literal)dn.Controls[0].Controls[0]; if (!string.IsNullOrEmpty(lt.Text)) { dn.Controls[0].Controls.Add(new LiteralControl("</br>")); dn.Controls[0].Controls.Add(new System.Web.UI.WebControls.Image() { Width = 100, Height = 100, ID = "Image" + row.ToString() + cellPosition.ToString(), ImageUrl = UtilsConfig.ImageKeepFullURL ? lt.Text : lt.Text.Contains("http")? lt.Text: baseurl + lt.Text, ToolTip = UtilsConfig.ImageKeepFullURL ? lt.Text : lt.Text.Contains("http") ? lt.Text : baseurl + lt.Text }); } } } } }