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 void CreateEnvelope()
        {
            // Create the envelope information
            DocuSignAPI.EnvelopeInformation envelopeInfo = new DocuSignAPI.EnvelopeInformation();
            envelopeInfo.Subject    = Request.Form["subject"];
            envelopeInfo.EmailBlurb = Request.Form["emailBlurb"];
            envelopeInfo.AccountId  = Session["APIAccountId"].ToString();

            // Add any reminders
            if (!String.IsNullOrEmpty(Request.Form["reminders"]))
            {
                DateTime remind     = Convert.ToDateTime(Request.Form["reminders"]);
                int      difference = (remind - DateTime.Today).Days;

                if (envelopeInfo.Notification == null)
                {
                    envelopeInfo.Notification = new DocuSignAPI.Notification();
                }
                envelopeInfo.Notification.Reminders = new DocuSignAPI.Reminders();
                envelopeInfo.Notification.Reminders.ReminderEnabled   = true;
                envelopeInfo.Notification.Reminders.ReminderDelay     = difference.ToString();
                envelopeInfo.Notification.Reminders.ReminderFrequency = "2";
            }

            // Add any expirations
            if (!String.IsNullOrEmpty(Request.Form["expiration"]))
            {
                DateTime expire     = Convert.ToDateTime(Request.Form["expiration"]);
                int      difference = (expire - DateTime.Today).Days;

                if (envelopeInfo.Notification == null)
                {
                    envelopeInfo.Notification = new DocuSignAPI.Notification();
                }

                envelopeInfo.Notification.Expirations = new DocuSignAPI.Expirations();
                envelopeInfo.Notification.Expirations.ExpireEnabled = true;
                envelopeInfo.Notification.Expirations.ExpireAfter   = difference.ToString();
                envelopeInfo.Notification.Expirations.ExpireWarn    = (difference - 2).ToString();
            }

            // Get all the recipients
            DocuSignAPI.Recipient[] recipients = ConstructRecipients();

            // Construct the template reference
            DocuSignAPI.TemplateReference templateReference = new DocuSignAPI.TemplateReference();
            templateReference.TemplateLocation = DocuSignAPI.TemplateLocationCode.Server;
            templateReference.Template         = TemplateTable.Value;
            templateReference.RoleAssignments  = CreateFinalRoleAssignments(recipients);

            if (Request.Form["SendNow"] != null)
            {
                SendNow(templateReference, envelopeInfo, recipients);
            }
            else
            {
                EmbedSending(templateReference, envelopeInfo, recipients);
            }
        }
        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 CreateEnvelope()
        {
            // Create the envelope information
            DocuSignAPI.EnvelopeInformation envelopeInfo = new DocuSignAPI.EnvelopeInformation();
            envelopeInfo.Subject = Request.Form["subject"];
            envelopeInfo.EmailBlurb = Request.Form["emailBlurb"];
            envelopeInfo.AccountId = Session["APIAccountId"].ToString();

            // Add any reminders
            if (!String.IsNullOrEmpty(Request.Form["reminders"]))
            {
                DateTime remind = Convert.ToDateTime(Request.Form["reminders"]);
                int difference = (remind - DateTime.Today).Days;

                if (envelopeInfo.Notification == null)
                {
                    envelopeInfo.Notification = new DocuSignAPI.Notification();
                }
                envelopeInfo.Notification.Reminders = new DocuSignAPI.Reminders();
                envelopeInfo.Notification.Reminders.ReminderEnabled = true;
                envelopeInfo.Notification.Reminders.ReminderDelay = difference.ToString();
                envelopeInfo.Notification.Reminders.ReminderFrequency = "2";
            }

            // Add any expirations
            if (!String.IsNullOrEmpty(Request.Form["expiration"]))
            {
                DateTime expire = Convert.ToDateTime(Request.Form["expiration"]);
                int difference = (expire - DateTime.Today).Days;

                if (envelopeInfo.Notification == null)
                {
                    envelopeInfo.Notification = new DocuSignAPI.Notification();
                }

                envelopeInfo.Notification.Expirations = new DocuSignAPI.Expirations();
                envelopeInfo.Notification.Expirations.ExpireEnabled = true;
                envelopeInfo.Notification.Expirations.ExpireAfter = difference.ToString();
                envelopeInfo.Notification.Expirations.ExpireWarn = (difference - 2).ToString();
            }

            // Get all the recipients
            DocuSignAPI.Recipient[] recipients = ConstructRecipients();

            // Construct the template reference
            DocuSignAPI.TemplateReference templateReference = new DocuSignAPI.TemplateReference();
            templateReference.TemplateLocation = DocuSignAPI.TemplateLocationCode.Server;
            templateReference.Template = TemplateTable.Value;
            templateReference.RoleAssignments = CreateFinalRoleAssignments(recipients);

            if (Request.Form["SendNow"] != null)
            {
                SendNow(templateReference, envelopeInfo, recipients);
            }
            else
            {
                EmbedSending(templateReference, envelopeInfo, recipients);
            }
        }
        protected void CreateEnvelope()
        {
            // Create the envelope information
            var envelopeInfo = new DocuSignAPI.EnvelopeInformation
                {
                    Subject = Request.Form[Keys.Subject],
                    EmailBlurb = Request.Form[Keys.EmailBlurb],
                    AccountId = Session[Keys.ApiAccountId].ToString()
                };

            // Add any reminders
            if (!String.IsNullOrEmpty(Request.Form[Keys.Reminders]))
            {
                DateTime remind = Convert.ToDateTime(Request.Form[Keys.Reminders]);
                int difference = (remind - DateTime.Today).Days;

                if (null == envelopeInfo.Notification)
                {
                    envelopeInfo.Notification = new DocuSignAPI.Notification();
                }
                envelopeInfo.Notification.Reminders = new DocuSignAPI.Reminders
                    {
                        ReminderEnabled = true,
                        ReminderDelay = difference.ToString(),
                        ReminderFrequency = "2"
                    };
            }

            // Add any expirations
            if (!String.IsNullOrEmpty(Request.Form[Keys.Expiration]))
            {
                DateTime expire = Convert.ToDateTime(Request.Form[Keys.Expiration]);
                int difference = (expire - DateTime.Today).Days;

                if (null == envelopeInfo.Notification)
                {
                    envelopeInfo.Notification = new DocuSignAPI.Notification();
                }

                envelopeInfo.Notification.Expirations = new DocuSignAPI.Expirations
                    {
                        ExpireEnabled = true,
                        ExpireAfter = difference.ToString(),
                        ExpireWarn = (difference - 2).ToString()
                    };
            }

            // Get all the recipients
            var recipients = ConstructRecipients();

            // Construct the template reference
            var templateReference = new DocuSignAPI.TemplateReference
                {
                    TemplateLocation = DocuSignAPI.TemplateLocationCode.Server,
                    Template = TemplateTable.Value,
                    RoleAssignments = CreateFinalRoleAssignments(recipients)
                };

            if (null != Request.Form[Keys.SendNow])
            {
                SendNow(templateReference, envelopeInfo, recipients);
            }
            else //Edit
            {
                EmbedSending(templateReference, envelopeInfo, recipients);
            }
        }
        protected void CreateEnvelope()
        {
            // Create the envelope information
            var envelopeInfo = new DocuSignAPI.EnvelopeInformation
            {
                Subject    = Request.Form[Keys.Subject],
                EmailBlurb = Request.Form[Keys.EmailBlurb],
                AccountId  = Session[Keys.ApiAccountId].ToString()
            };

            // Add any reminders
            if (!String.IsNullOrEmpty(Request.Form[Keys.Reminders]))
            {
                DateTime remind     = Convert.ToDateTime(Request.Form[Keys.Reminders]);
                int      difference = (remind - DateTime.Today).Days;

                if (null == envelopeInfo.Notification)
                {
                    envelopeInfo.Notification = new DocuSignAPI.Notification();
                }
                envelopeInfo.Notification.Reminders = new DocuSignAPI.Reminders
                {
                    ReminderEnabled   = true,
                    ReminderDelay     = difference.ToString(),
                    ReminderFrequency = "2"
                };
            }

            // Add any expirations
            if (!String.IsNullOrEmpty(Request.Form[Keys.Expiration]))
            {
                DateTime expire     = Convert.ToDateTime(Request.Form[Keys.Expiration]);
                int      difference = (expire - DateTime.Today).Days;

                if (null == envelopeInfo.Notification)
                {
                    envelopeInfo.Notification = new DocuSignAPI.Notification();
                }

                envelopeInfo.Notification.Expirations = new DocuSignAPI.Expirations
                {
                    ExpireEnabled = true,
                    ExpireAfter   = difference.ToString(),
                    ExpireWarn    = (difference - 2).ToString()
                };
            }

            // Get all the recipients
            var recipients = ConstructRecipients();

            // Construct the template reference
            var templateReference = new DocuSignAPI.TemplateReference
            {
                TemplateLocation = DocuSignAPI.TemplateLocationCode.Server,
                Template         = TemplateTable.Value,
                RoleAssignments  = CreateFinalRoleAssignments(recipients)
            };

            if (null != Request.Form[Keys.SendNow])
            {
                SendNow(templateReference, envelopeInfo, recipients);
            }
            else //Edit
            {
                EmbedSending(templateReference, envelopeInfo, recipients);
            }
        }