protected void Page_Load(object sender, EventArgs e) { if (Session["Envelope"] != null) { Signing.Envelope env = (Signing.Envelope)Session["Envelope"]; Signing.DocuSignWeb.EnvelopeStatus stat = env.RetrieveFullStatus(); lblApplicationType.Text = "Auto Insurance Agreement"; lblEnvelopeId.Text = env.EnvelopeId; lblStatus.Text = stat.Status.ToString(); } }
protected void downloadPdf_Click(object sender, EventArgs e) { Debug.WriteLine("Session ID:" + Session.SessionID); Signing.Envelope envelope = (Signing.Envelope)Session["Envelope"]; byte[] bytes = envelope.RetrievePdfBytes(); Response.Clear(); Response.AddHeader("Content-Type", "application/pdf"); Response.AddHeader("Content-Length", bytes.Length.ToString()); Response.AddHeader("Content-Disposition", "attachment; filename=envelope.pdf"); Response.BinaryWrite(bytes); Response.End(); }
public void SendEnvelope() { // ok, long method! // we need to build a Template that will be sent to docusign to create an envelope. A template is like a generic form // it has Roles (like Signer, Co-Signer, CC Recipient, etc) and form fields and documents predefined. // when we use a template we provide real recipients who will take on the Roles in the template, and we may supply data to // prefill any form fields, and we can even provide replacement documents (which we are not using here). A replacement document // would be useful in a case where you have a standard contract in your template, and you want to use the template, but replace the // contract with one that has some custom language specific to the deal. But, like I said, we're not doing that in this demo. // // if we selected the EmbeddedSending option then we will tell docusign to not send the envelope, but hold it // in a draft state, so that we can open it up here and make some changes to it. // // if we selected EmbeddedSigning, then we will tell docusign to send the envelope, and we will launch the signing // session here. // first, get our recipients List <Signing.DocuSignWeb.Recipient> recipients = makeRecipients(); // build a dictionary of form field values to pass in to the template Dictionary <string, string> formfields = new Dictionary <string, string>(); formfields.Add("VIN", carVIN.Text); formfields.Add("Make", carMake.Text); formfields.Add("Model", carModel.Text); // now build our template. Signing.DocuSignWeb.TemplateReference templateRef = makeTemplate(recipients, formfields); // we could potentially have multiple templates in an envelope, so the method call takes an array. List <Signing.DocuSignWeb.TemplateReference> templateRefs = new List <Signing.DocuSignWeb.TemplateReference>(); templateRefs.Add(templateRef); // envelope info - This holds additional customization info - some info is similar to a mailing label // on a paper envelope, and other info controls how the envelope will be processed. See API docs for more info. Signing.DocuSignWeb.EnvelopeInformation envelopeInfo = new Signing.DocuSignWeb.EnvelopeInformation(); envelopeInfo.EmailBlurb = "This envelope was sent from the Auto Insurance Sample of the DocuSign SDK."; envelopeInfo.Subject = "InsuranceCo Auto Rider"; envelopeInfo.AccountId = (string)Session["AccountID"]; // ActivateEnvelope flag - this indicates whether we want to send the envelope immediately // or leave it in the drafts folder. // We are using the value of the embeddedSending checkbox to determine this bool activateEnvelope = embeddedSigning.Checked; //bundle all into params for call Signing.Envelope env = null; try { Session["Envelope"] = env = Signing.Envelope.CreateEnvelopeFromServerTemplates(base.GetAPICredentials(), templateRefs.ToArray(), recipients.ToArray(), envelopeInfo, activateEnvelope); } catch (Exception excp) { base.GoToErrorPage(excp.Message); } // Now if we are using either embedded sending or embedded signing we need to get a token to launch the // embedded host page. If not, then redirect to the status page string nextPageURL = ""; // get the url of the page we want to go to when we're done with embedded session Uri retUri = new Uri(Request.Url.AbsoluteUri.Replace("AutoAppApply.aspx", "pop.html"), UriKind.Absolute); if (embeddedSigning.Checked) { // get embeddedsigning token for applicant to sign Signing.DocuSignWeb.RequestRecipientTokenAuthenticationAssertion assert = ApiHelper.MakeRecipientTokenAuthAssert(DateTime.Now.Ticks.ToString()); Signing.DocuSignWeb.RequestRecipientTokenClientURLs clientURLs = Signing.Envelope.StandardUrls(retUri, recipients[0].UserName); try { Session["EmbeddedToken"] = env.RequestRecipientToken(recipients[0], assert, clientURLs); nextPageURL = "EmbeddedHost.aspx"; } catch (Exception excp) { base.GoToErrorPage(excp.Message); } } else if (embeddedSending.Checked) { // get sending token just to demo the function. You typically would not let someone send their own application try { Session["EmbeddedToken"] = env.RequestSenderToken(retUri.ToString()); nextPageURL = "EmbeddedHost.aspx"; } catch (Exception excp) { base.GoToErrorPage(excp.Message); } } else { nextPageURL = "AutoAppStatus.aspx"; } Response.Redirect(nextPageURL, true); }