Example #1
0
        //==========================================================================================
        // *** Walkthrough #6 - Get Documents List and Download Documents
        //==========================================================================================
        private void GetDocsListAndDownloadDocuments()
        {
            //*****************************************************************
            // ENTER VALUES FOR FOLLOWING VARIABLES!
            //*****************************************************************
            string AccountEmail = "***";
            string AccountPassword = "******";
            string EnvelopeId = "***";
            //*****************************************************************

            // user credentials 
            Account account = new Account();
            account.Email = AccountEmail;
            account.Password = AccountPassword;

            // make the login call (retrieves your baseUrl and accountId)
            bool result = account.Login();
            if (!result)
            {
                Console.WriteLine("Login API call failed for user {0}.\nError Code:  {1}\nMessage:  {2}", account.Email, account.RestError.errorCode, account.RestError.message);
                return;
            }

            // create envelope object and assign login info
            Envelope envelope = new Envelope();
            envelope.Login = account;

            // assign the passed in envelope id to the newly created envelope object
            envelope.EnvelopeId = EnvelopeId;

            // get the envelope's documents 
            List<EnvelopeDocument> envDocs = envelope.GetDocuments();

            // loop through the documents and display some info about them
            foreach (var doc in envDocs)
            {
                Console.WriteLine("Document id {0} is named {1}.", doc.documentId, doc.name);
            }

            // now let's download the actual document bytes and store in a local file in the application's main directory
            string applicationPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            byte[] completedDocBytes = envelope.GetCompletedDocument(EnvelopeId, true);

            // set local document name here, currently using envelopeID.pdf as name
            string localFileName = applicationPath + "\\" + EnvelopeId + ".pdf";

            // combine all envelope documents (including certificate) into local PDF file
            File.WriteAllBytes(localFileName, completedDocBytes);

            Console.WriteLine("Completed documents have been downloaded to {0}", localFileName);
        }