static void Main(string[] args)
        {
            #region DocuSign Envelope
            // create DocuSign envelope
            Console.WriteLine("Creating a DocuSign envelope...");
            string envelopeID = CreateDocuSignEnvelope();
            Console.WriteLine("Envelope ID sent to " + ConfigurationManager.AppSettings["RecipientEmail"] + ": " + envelopeID);
            if ((bool)Convert.ToBoolean(ConfigurationManager.AppSettings["ShowSharePointDemo"]) == true)
            {
                //Configured to run SharePoint demo - prompt accordingly
                Console.WriteLine("After envelope is completed (signed), press any key to continue to upload to SharePoint...");
            }
            else
            {
                //Not configured to run SharePoint demo
                Console.WriteLine("Press any key to exit...");
            }

            Console.ReadKey();
            #endregion

            #region SharePoint
            if ((bool)Convert.ToBoolean(ConfigurationManager.AppSettings["ShowSharePointDemo"]) == true)
            {
                Console.WriteLine("Uploading COMPLETED envelope {0} to SharePoint...", envelopeID);
                // create completed envelope external repository folder in SharePoint
                SharePointOnlineHelper.CreateFolderForEnvelope(envelopeID);

                DocuSignEnvelopeHelper.UploadDocuSignEnvelopeToSharePoint(accountID, envelopeID);
                Console.WriteLine("Done uploading envelope {0} to SharePoint", envelopeID);
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
            #endregion
        }
Пример #2
0
        /// <summary>
        /// UploadDocuSignEnvelopeToSharePoint - uploads a COMPLETED DocuSign envelope to a Sharepoint folder named as envelopeID
        /// </summary>
        /// <param name="accountID"></param>
        /// <param name="envelopeID"></param>
        static public void UploadDocuSignEnvelopeToSharePoint(string accountID, string envelopeID)
        {
            string userId             = ConfigurationManager.AppSettings["UserId"];
            string oauthBasePath      = ConfigurationManager.AppSettings["OAuthBasePath"];
            string integratorKey      = ConfigurationManager.AppSettings["IntegratorKey"];
            string privateKeyFilename = AppContext.BaseDirectory + "PrivateKey.txt";
            string host           = ConfigurationManager.AppSettings["Host"];
            int    expiresInHours = 1;

            string siteUrl       = ConfigurationManager.AppSettings["SiteUrl"];
            string targetLibrary = ConfigurationManager.AppSettings["TargetLibrary"];
            string userName      = ConfigurationManager.AppSettings["UserName"];
            string password      = ConfigurationManager.AppSettings["Password"];

            ApiClient apiClient = new ApiClient(host);

            apiClient.ConfigureJwtAuthorizationFlow(integratorKey, userId, oauthBasePath, privateKeyFilename, expiresInHours);

            /////////////////////////////////////////////////////////////////
            // STEP 1: LOGIN API
            /////////////////////////////////////////////////////////////////
            AuthenticationApi authApi   = new AuthenticationApi(apiClient.Configuration);
            LoginInformation  loginInfo = authApi.Login();

            // find the default account for this user
            foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
            {
                if (loginAcct.IsDefault == "true")
                {
                    accountID = loginAcct.AccountId;

                    string[] separatingStrings = { "/v2" };

                    // Update ApiClient with the new base url from login call
                    apiClient = new ApiClient(loginAcct.BaseUrl.Split(separatingStrings, StringSplitOptions.RemoveEmptyEntries)[0]);
                    break;
                }
            }

            /////////////////////////////////////////////////////////////////
            // STEP 2: GET DOCUMENTS API
            /////////////////////////////////////////////////////////////////

            EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);
            Envelope     envInfo      = envelopesApi.GetEnvelope(accountID, envelopeID);

            if (envInfo.Status.ToLower().CompareTo("completed") == 0)
            {
                // upload all documents for accountID and envelopeID
                MemoryStream docStream = GetAllDocuments(accountID, envelopeID);
                Console.WriteLine("Uploading to SharePoint all documents for envelope {0}", envelopeID);
                string fileName = envInfo.EnvelopeId + ".pdf";
                SharePointOnlineHelper.UploadFileStreamToSharePoint(siteUrl, userName, password, targetLibrary, docStream, fileName, envelopeID, false);

                // upload Certificate of Completion for accountID and envelopeID
                Console.WriteLine("Uploading to SharePoint the Certificate Of Completion for envelope {0}", envelopeID);
                MemoryStream cocStream = GetCertificateOfCompletion(accountID, envelopeID);
                fileName = "COC_" + envInfo.EnvelopeId + ".pdf";
                SharePointOnlineHelper.UploadFileStreamToSharePoint(siteUrl, userName, password, targetLibrary, cocStream, fileName, envelopeID, false);
            }
            else
            {
                Console.WriteLine("Download DocuSign documents can be performed only for COMPLETED envelopes.");
            }
        }