protected void btnSubmit_Click(object sender, EventArgs e) { try { if (ddlFormat.SelectedValue == "jpg") { if (ddlConvert.SelectedValue == "html") { grabzItClient.HTMLToImage(txtHTML.Text); } else { grabzItClient.URLToImage(txtURL.Text); } } else if (ddlFormat.SelectedValue == "docx") { if (ddlConvert.SelectedValue == "html") { grabzItClient.HTMLToDOCX(txtHTML.Text); } else { grabzItClient.URLToDOCX(txtURL.Text); } } else if (ddlFormat.SelectedValue == "csv") { if (ddlConvert.SelectedValue == "html") { grabzItClient.HTMLToTable(txtHTML.Text); } else { grabzItClient.URLToTable(txtURL.Text); } } else if (ddlFormat.SelectedValue == "gif") { grabzItClient.URLToAnimation(txtURL.Text); } else { if (ddlConvert.SelectedValue == "html") { grabzItClient.HTMLToPDF(txtHTML.Text); } else { grabzItClient.URLToPDF(txtURL.Text); } } if (UseCallbackHandler) { grabzItClient.ScreenShotComplete += grabzIt_ScreenShotComplete; grabzItClient.Save(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + "GrabzIt.ashx"); lblMessage.Text = "Processing..."; lblMessage.CssClass = string.Empty; lblMessage.Style.Add("color", "green"); lblMessage.Style.Add("font-weight", "bold"); } else { grabzItClient.SaveTo(Server.MapPath("~/results/" + Guid.NewGuid().ToString() + "." + ddlFormat.SelectedValue)); } } catch (Exception ex) { lblMessage.Text = ex.Message; lblMessage.Style.Clear(); lblMessage.CssClass = "error"; } }
public ActionResult Index(FormModel form) { GrabzItClient grabzItClient = GrabzItClient.Create(ConfigurationManager.AppSettings["ApplicationKey"], ConfigurationManager.AppSettings["ApplicationSecret"]); form.UseCallbackHandler = !HttpContext.Request.IsLocal; try { if (form.Format == "jpg") { if (form.Convert == "html") { grabzItClient.HTMLToImage(form.HTML); } else { grabzItClient.URLToImage(form.URL); } } else if (form.Format == "docx") { if (form.Convert == "html") { grabzItClient.HTMLToDOCX(form.HTML); } else { grabzItClient.URLToDOCX(form.URL); } } else if (form.Format == "csv") { if (form.Convert == "html") { grabzItClient.HTMLToTable(form.HTML); } else { grabzItClient.URLToTable(form.URL); } } else if (form.Format == "gif") { grabzItClient.URLToAnimation(form.URL); } else { if (form.Convert == "html") { grabzItClient.HTMLToPDF(form.HTML); } else { grabzItClient.URLToPDF(form.URL); } } if (form.UseCallbackHandler) { grabzItClient.Save(HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Authority + HttpContext.Request.ApplicationPath + "Home/Handler"); } else { grabzItClient.SaveTo(Server.MapPath("~/results/" + Guid.NewGuid().ToString() + "." + form.Format)); } form.Message = "Processing..."; } catch (Exception ex) { form.Error = ex.Message; } return(View(form)); }