protected void EmbedSending(DocuSignAPI.TemplateReference templateReference, DocuSignAPI.EnvelopeInformation envelopeInfo, DocuSignAPI.Recipient[] recipients) { DocuSignAPI.APIServiceSoapClient client = CreateAPIProxy(); try { // Create the envelope using the specified template, but don't send it (note the last parameter) DocuSignAPI.EnvelopeStatus status = client.CreateEnvelopeFromTemplates(new DocuSignAPI.TemplateReference[] { templateReference }, recipients, envelopeInfo, false); base.AddEnvelopeID(status.EnvelopeID); // If it created successfully, redirect to the embedded host if (status.Status == DocuSignAPI.EnvelopeStatusCode.Created) { string navURL = String.Format("{0}?envelopeID={1}&accountID={2}&source=Template", "EmbeddedHost.aspx", status.EnvelopeID, envelopeInfo.AccountId); Response.Redirect(navURL, false); } } catch (Exception ex) { base.GoToErrorPage(ex.Message); } }
protected System.Web.UI.HtmlControls.HtmlGenericControl CreateEnvelopeTable(DocuSignAPI.EnvelopeStatus status) { System.Web.UI.HtmlControls.HtmlTable envelopeTable = new System.Web.UI.HtmlControls.HtmlTable(); System.Web.UI.HtmlControls.HtmlGenericControl envelopeDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); int recipIndex = 0; foreach (DocuSignAPI.RecipientStatus recipient in status.RecipientStatuses) { System.Web.UI.HtmlControls.HtmlGenericControl info = new System.Web.UI.HtmlControls.HtmlGenericControl("p"); String recipId = "Recipient_Detail_" + status.EnvelopeID + "_" + recipient.RoutingOrder + "_" + recipient.UserName + "_" + recipient.Email + "_" + recipIndex++; info.InnerHtml = "<a href=\"javascript:toggle('" + recipId + "');\"><img src=\"images/plus.png\"></a> Recipient - " + recipient.UserName + ": " + recipient.Status.ToString(); if (recipient.Status != DocuSignAPI.RecipientStatusCode.Completed && recipient.ClientUserId != null) { info.InnerHtml += " <input type=\"submit\" id=\"" + status.EnvelopeID + "\" value=\"Start Signing\" name=\"DocEnvelope+" + status.EnvelopeID + "&Email+" + recipient.Email + "&UserName+" + recipient.UserName + "&CID+" + recipient.ClientUserId + "\">"; } if (recipient.TabStatuses != null) { System.Web.UI.HtmlControls.HtmlGenericControl tabs = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); foreach (DocuSignAPI.TabStatus tab in recipient.TabStatuses) { System.Web.UI.HtmlControls.HtmlGenericControl t = new System.Web.UI.HtmlControls.HtmlGenericControl("p"); t.InnerHtml = tab.TabName + ": " + tab.TabValue; tabs.Controls.Add(t); } tabs.Attributes["id"] = recipId; tabs.Attributes["class"] = "detail"; info.Controls.Add(tabs); } envelopeDiv.Controls.Add(info); } System.Web.UI.HtmlControls.HtmlGenericControl documents = new System.Web.UI.HtmlControls.HtmlGenericControl("p"); documents.InnerHtml = "<a href=\"javascript:toggle('" + status.EnvelopeID + "_Detail_Documents" + "');\"><img src=\"images/plus.png\"></a> Documents"; if (status.Status == DocuSignAPI.EnvelopeStatusCode.Completed) { documents.InnerHtml += " <input type=\"submit\" id=\"" + status.EnvelopeID + "\" value=\"Download\" name=\"" + status.EnvelopeID + "\";>"; } envelopeDiv.Controls.Add(documents); if (status.DocumentStatuses != null) { System.Web.UI.HtmlControls.HtmlGenericControl documentDiv = new System.Web.UI.HtmlControls.HtmlGenericControl("div"); foreach (DocuSignAPI.DocumentStatus document in status.DocumentStatuses) { System.Web.UI.HtmlControls.HtmlGenericControl info = new System.Web.UI.HtmlControls.HtmlGenericControl("p"); info.InnerHtml = document.Name; documentDiv.Controls.Add(info); } documentDiv.Attributes["id"] = status.EnvelopeID + "_Detail_Documents"; documentDiv.Attributes["class"] = "detail"; envelopeDiv.Controls.Add(documentDiv); } return(envelopeDiv); }
protected void SignFirst(DocuSignAPI.EnvelopeStatus status) { // Create the assertion using the current time, password and demo information DocuSignAPI.RequestRecipientTokenAuthenticationAssertion assertion = new DocuSignAPI.RequestRecipientTokenAuthenticationAssertion(); assertion.AssertionID = new Guid().ToString(); assertion.AuthenticationInstant = DateTime.Now; assertion.AuthenticationMethod = DocuSignAPI.RequestRecipientTokenAuthenticationAssertionAuthenticationMethod.Password; assertion.SecurityDomain = "DocuSignSample"; DocuSignAPI.RecipientStatus recipient = status.RecipientStatuses[0]; // Construct the URLs to which the iframe will redirect upon every event DocuSignAPI.RequestRecipientTokenClientURLs urls = new DocuSignAPI.RequestRecipientTokenClientURLs(); String urlBase = Request.Url.AbsoluteUri.Replace("EmbedDocuSign.aspx", "pop.html") + "?source=embed"; urls.OnSigningComplete = urlBase + "&event=SignComplete1"; urls.OnViewingComplete = urlBase + "&event=ViewComplete1"; urls.OnCancel = urlBase + "&event=Cancel1"; urls.OnDecline = urlBase + "&event=Decline1"; urls.OnSessionTimeout = urlBase + "&event=Timeout1"; urls.OnTTLExpired = urlBase + "&event=TTLExpired1"; urls.OnIdCheckFailed = urlBase + "&event=IDCheck1"; urls.OnAccessCodeFailed = urlBase + "&event=AccessCode1"; urls.OnException = urlBase + "&event=Exception1"; DocuSignAPI.APIServiceSoapClient client = CreateAPIProxy(); String token = null; try { // Request the token for a specific recipient token = client.RequestRecipientToken(status.EnvelopeID, recipient.ClientUserId, recipient.UserName, recipient.Email, assertion, urls); } catch (Exception ex) { base.GoToErrorPage(ex.Message); } // Set the signer message if (_oneSigner) { signerMessage = "Have the signer fill out the Envelope"; } else { signerMessage = "Have the first signer fill out the Envelope"; } messagediv.Visible = true; // Set the source of the iframe to the token hostiframe.Visible = true; hostiframe.Attributes["src"] = token; }
protected void CreateAndSend() { DocuSignAPI.EnvelopeStatus status = null; buttonTable.Visible = false; // Construct the envelope basics DocuSignAPI.Envelope envelope = new DocuSignAPI.Envelope(); envelope.Subject = "DocuSign API SDK Example"; envelope.EmailBlurb = "This envelope demonstrates embedded signing"; envelope.AccountId = Session["APIAccountId"].ToString(); // Create the recipient(s) envelope.Recipients = ConstructRecipients(); // Add the document to the envelope DocuSignAPI.Document stockDocument = new DocuSignAPI.Document(); stockDocument.PDFBytes = Resources.DocuSign_Demo__111_PDF; stockDocument.Name = "Demo Document"; stockDocument.ID = "1"; stockDocument.FileExtension = "pdf"; envelope.Documents = new DocuSignAPI.Document[] { stockDocument }; // Add the tabs to the envelope envelope.Tabs = AddTabs(envelope.Recipients.Length); DocuSignAPI.APIServiceSoapClient client = CreateAPIProxy(); try { // Send the envelope and temporarily store the status in the session status = client.CreateAndSendEnvelope(envelope); if (status.SentSpecified) { Session["EnvelopeStatus"] = status; base.AddEnvelopeID(status.EnvelopeID); // Start the first signer SignFirst(status); } } catch (Exception ex) { base.GoToErrorPage(ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { if (!LoggedIn()) { Response.Redirect("LogIn.aspx"); } if (!Page.IsPostBack && Request.Form["__EVENTTARGET"] != logoutCtrlName) { // Check to see if we're coming back after signing as the first signer DocuSignAPI.EnvelopeStatus status = (DocuSignAPI.EnvelopeStatus)Session["EnvelopeStatus"]; if (status == null || Request["event"] == null) { hostiframe.Visible = false; } // If we are, start the second signer else if (Request["event"].ToString() == "SignComplete1" && status.RecipientStatuses.Length > 1) { SignSecond(status); } // If we're finished altogether, or if one of the signers exited without completed, go to the status page else if ((Request["event"].ToString() == "SignComplete1" && status.RecipientStatuses.Length == 1) || Request["event"].ToString() == "SignComplete2" || !(Request["event"].ToString() == null)) { Session["EnvelopeStatus"] = null; Response.Redirect("GetStatusAndDocs.aspx", false); } } else { // Create and send the envelope using the two different options. if (Request.Form["OneSigner"] != null) { _oneSigner = true; CreateAndSend(); } else if (Request.Form["TwoSigners"] != null) { _oneSigner = false; CreateAndSend(); } } }
protected void SendNow(DocuSignAPI.Envelope envelope) { DocuSignAPI.APIServiceSoapClient client = CreateAPIProxy(); try { // Create and send the envelope in one step DocuSignAPI.EnvelopeStatus status = client.CreateAndSendEnvelope(envelope); // If we succeeded, go to the status if (status.SentSpecified) { base.AddEnvelopeID(status.EnvelopeID); Response.Redirect("GetStatusAndDocs.aspx", false); } } catch (Exception ex) { base.GoToErrorPage(ex.Message); } }
protected void SendNow(DocuSignAPI.TemplateReference templateReference, DocuSignAPI.EnvelopeInformation envelopeInfo, DocuSignAPI.Recipient[] recipients) { DocuSignAPI.APIServiceSoapClient client = CreateAPIProxy(); try { // Create the envelope using the specified template, and send it (note the last parameter) DocuSignAPI.EnvelopeStatus status = client.CreateEnvelopeFromTemplates(new DocuSignAPI.TemplateReference[] { templateReference }, recipients, envelopeInfo, true); base.AddEnvelopeID(status.EnvelopeID); if (status.SentSpecified) { Response.Redirect("GetStatusAndDocs.aspx", false); } } catch (Exception ex) { base.GoToErrorPage(ex.Message); } }
protected void EmbedSending(DocuSignAPI.Envelope envelope) { DocuSignAPI.APIServiceSoapClient client = CreateAPIProxy(); try { // Create the envelope (but don't send it!) DocuSignAPI.EnvelopeStatus status = client.CreateEnvelope(envelope); base.AddEnvelopeID(status.EnvelopeID); // If it created successfully, redirect to the embedded host if (status.Status == DocuSignAPI.EnvelopeStatusCode.Created) { string navURL = String.Format("{0}?envelopeID={1}&accountID={2}&source=Document", "EmbeddedHost.aspx", status.EnvelopeID, envelope.AccountId); Response.Redirect(navURL, false); } } catch (Exception ex) { base.GoToErrorPage(ex.Message); } }