protected void ImageStart_OnClick(Object sender, EventArgs e) { Server.Application.ImageResponse imageResponse = null; String objectType = String.Empty; Int64 objectId = 0; Boolean render = false; objectType = Request.QueryString["ObjectType"]; objectId = Convert.ToInt64(Request.QueryString["ObjectId"]); render = Convert.ToBoolean(Request.QueryString["Render"]); try { switch (objectType) { case "EntityCorrespondence": imageResponse = MercuryApplication.EntityCorrespondenceImageGet(objectId, render); HandleResponse(imageResponse); break; default: SetException(new ApplicationException("Unknown or unsupported Object Type: " + objectType)); break; } } catch (Exception exception) { SetException(exception); } return; }
private void HandleResponse(Server.Application.ImageResponse imageResponse) { String objectType = String.Empty; Int64 objectId = 0; Boolean render = false; objectType = Request.QueryString["ObjectType"]; objectId = Convert.ToInt64(Request.QueryString["ObjectId"]); render = Convert.ToBoolean(Request.QueryString["Render"]); LoadingProgressImage.Style.Add("display", "none"); if (imageResponse == null) { SetException(new ApplicationException("Image not found or unable to generate for " + objectType + " [" + objectId + "].", MercuryApplication.LastException)); return; } if ((imageResponse != null) ? ((!String.IsNullOrWhiteSpace(imageResponse.ImageBase64)) && (!imageResponse.HasException)) : false) { System.IO.MemoryStream image = new System.IO.MemoryStream(Convert.FromBase64String(imageResponse.ImageBase64)); Response.ContentType = imageResponse.MimeType; Response.AddHeader("content-disposition", "inline; filename=" + imageResponse.ImageName); Response.BinaryWrite(image.ToArray()); // Response.End (); } else { SetException(new ApplicationException("Image not found or unable to generate for " + objectType + " [" + objectId + "].", MercuryApplication.LastException)); } }