Fetch Document Size in DocuSign using C#

38 views Asked by At

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!

2

There are 2 answers

0
Inbar Gazit On BEST ANSWER

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
   }
}
0
Larry K On

Afaik, we don't have an API call for the document size without the documents themselves. Sorry.

Added

I figured it went without saying that you can download the docs, obtain their size, then throw away the documents themselves. I would not advise this software pattern.

Instead, figure out how to store the documents once you've downloaded them.

HEAD

Unfortunately, DocuSign does not support the HEAD HTTP command which is often used to just get the response size without the response body itself.