Search code examples
c#sizedocusignapidocusign-sdk

Fetch Document Size in DocuSign using C#


I have been able to fetch envelope documents in DocuSign account using C#.

EnvelopeDocumentsResult docs = envelopesApi.ListDocuments(accountId, envelope.EnvelopeId);

if (docs != null && docs.EnvelopeDocuments.Count > 0)
{
    foreach (EnvelopeDocument doc in docs.EnvelopeDocuments)
    {
        string size = doc.SizeBytes;
        .....
        .....

However, the "SizeBytes" property of the document is null. I need to know the Size of document without downloading the document. What is the best possible solution available for obtaining Size of document in Envelope.

Thanks!


Solution

  • You can do it, but you have to go document by document, download each document and check its size. That potentially means sending lots of bits for the sole purpose of counting them, but it will give you the answer.

    Here is C# code to augment yours:

    if (docs != null && docs.EnvelopeDocuments.Count > 0)
    {
        foreach (EnvelopeDocument doc in docs.EnvelopeDocuments)
        {
            Stream results = envelopesApi.GetDocument(accountId, envelopeId, doc.DocumentId);
            var length = results.Length; // TADA
       }
    }