public bool GetDocumentAndStatus(string envelopeID, string folderPath) { var accountID = AuthenticateJWT(); var envelopesApi = new ds.Api.EnvelopesApi(); var envelope = envelopesApi.GetEnvelope(accountID, envelopeID); if (envelope.Status == "completed") { // Download the docs var docsList = envelopesApi.ListDocuments(accountID, envelopeID); int docCount = docsList.EnvelopeDocuments.Count; string filePath = null; System.IO.FileStream fs = null; for (int i = 0; i < docCount; i++) { // GetDocument() API call returns a MemoryStream System.IO.MemoryStream docStream = (System.IO.MemoryStream)envelopesApi.GetDocument(accountID, envelopeID, docsList.EnvelopeDocuments[i].DocumentId); // save the document to local file system System.IO.Directory.CreateDirectory(folderPath); filePath = folderPath + "\\" + System.IO.Path.GetRandomFileName() + ".pdf"; fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create); docStream.Seek(0, System.IO.SeekOrigin.Begin); docStream.CopyTo(fs); fs.Close(); Console.WriteLine("Envelope Document {0} has been downloaded to: {1}", i, filePath); } return(true); } else { return(false); } }
public Models.Envelope GetSignatureRedirect(ClientConfig config) { // verify auth info if (string.IsNullOrWhiteSpace(config.AccountID)) { AuthConfig = config.AuthConfig; config.AccountID = AuthenticateJWT(); } ds.Model.EnvelopeDefinition def = new ds.Model.EnvelopeDefinition(); def.EmailSubject = config.EmailSubject; // Add a document to the envelope ds.Model.Document doc = new ds.Model.Document(); doc.DocumentBase64 = System.Convert.ToBase64String(config.DocumentBytes); doc.Name = config.DocumentFilename; doc.DocumentId = "1"; def.Documents = new List <ds.Model.Document>() { doc }; // Add a recipient to sign the documeent ds.Model.Signer signer = new ds.Model.Signer(); signer.Email = config.SignerEmail; signer.Name = config.SignerName; signer.RecipientId = "2"; signer.ClientUserId = config.SignerID; // must set |clientUserId| to embed the recipient! // Create a |SignHere| tab somewhere on the document for the recipient to sign signer.Tabs = new ds.Model.Tabs(); signer.Tabs.SignHereTabs = new List <ds.Model.SignHere>(); ds.Model.SignHere signHere = new ds.Model.SignHere(); signHere.DocumentId = "1"; signHere.RecipientId = "1"; signHere.AnchorXOffset = "0"; signHere.AnchorYOffset = "0"; signHere.AnchorUnits = "inches"; signHere.AnchorString = "SIGN_HERE_PLEASE"; signer.Tabs.SignHereTabs.Add(signHere); def.Recipients = new ds.Model.Recipients(); def.Recipients.Signers = new List <ds.Model.Signer>(); def.Recipients.Signers.Add(signer); // set envelope status to "sent" to immediately send the signature request def.Status = "sent"; // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests) ds.Api.EnvelopesApi envelopesApi = new ds.Api.EnvelopesApi(); ds.Model.EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(config.AccountID, def); ds.Model.RecipientViewRequest viewOptions = new ds.Model.RecipientViewRequest() { ReturnUrl = config.ReturnURL, ClientUserId = config.SignerID, // must match clientUserId set in step #2! AuthenticationMethod = "password", UserName = def.Recipients.Signers[0].Name, Email = def.Recipients.Signers[0].Email }; // create the recipient view (aka signing URL) ds.Model.ViewUrl recipientView = envelopesApi.CreateRecipientView( config.AccountID, envelopeSummary.EnvelopeId, viewOptions); return(new Models.Envelope() { EnvelopeID = envelopeSummary.EnvelopeId, RedirectURL = recipientView.Url }); }