Hattabitos | Posts: 24

Download signed documents with a date range

0 votes
We have a user that would like to download all signed documents for the past week under his account. Would anyone have a sample code on how to do that? Thanks,

harishaidary | Posts: 1812

Reply to: Download signed documents with a date range

0 votes
Hey, Here's an example code on how you would download signed documents within a date range:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Silanis.ESL.SDK;
using Silanis.ESL.SDK.Builder;
using System.Diagnostics;
using System.IO;

namespace DownloadDocumentsDateRange
{
    class DownloadDocuments
    {
        //replace apiKey placeholder with your own value
        private static String apiUrl = "https://sandbox.e-signlive.com/api";
        private static String apiKey = "your_api_key";

        public static void Main(string[] args)
        {
            EslClient eslClient = new EslClient(apiKey, apiUrl);

            //starting point to retrieve completed packages
            int index = 1;

            //Retrieve first 50 completed packages. Packages are returned as a page from eSignLive.
            Page completed_packages = eslClient.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus.COMPLETED, new PageRequest(index, 50), DateTime.Today.AddDays(-7), DateTime.Now);

            while (index = completed_packages.TotalElements)
            {
                foreach (DocumentPackage package in completed_packages)
                {
                    //for each completed package, get the package id to download signed documents.
                    Debug.WriteLine("Downloading package: " + package.Id + "...");
                    byte[] zipContent = eslClient.DownloadZippedDocuments(package.Id);
                    File.WriteAllBytes(Directory.GetCurrentDirectory() + "/package-documents-" + package.Id.ToString() + ".zip", zipContent);
                    index++;
                    Thread.Sleep(1000);
                }
                //Retrieve next 50 packages
                completed_packages = eslClient.PackageService.GetUpdatedPackagesWithinDateRange(DocumentPackageStatus.COMPLETED, new PageRequest(index, 50), DateTime.Today.AddDays(-7), DateTime.Now);
            }
            Debug.WriteLine("Downloaded All File!");
        }
    }
}
Let me know if anything is unclear :)

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off