Question

I was referring to the C# example here : http://iodocs.docusign.com/APIWalkthrough/getEnvelopeDocuments

This API actually downloads the document based on the envelope ID on the server.

However, for my use-case, I was wondering if there's a way to retrieve the document via API through a URL, instead of downloading it to the server.

Was it helpful?

Solution

Although it's not possible to link directly to DocuSign document(s) via URL, it is possible to display the documents in a browser (without having to download them to your server) when a user clicks a link on your site. Doing so simply requires that, onClick of the link, your code requests documents from DocuSign via API (as the example shows), and then immediately writes the response stream (byte array) to the browser (instead of writing it to a file).

You should be able to achieve this by replacing the "// read the response and store into a local file:" section (in the code example you link to) with something like the following:

// Write the response stream to the browser (render PDF in browser).
HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();
byte[] b = null;
using (Stream stream = webResponse.GetResponseStream())
using (MemoryStream ms = new MemoryStream())
{
    int count = 0;
    do
    {
        byte[] buf = new byte[1024];
        count = stream.Read(buf, 0, 1024);
        ms.Write(buf, 0, count);
    } while (stream.CanRead && count > 0);
    b = ms.ToArray();
}
Response.BufferOutput = true;
Response.ClearHeaders();
Response.AddHeader("content-disposition", "inline;filename=DSfile.pdf");
Response.ContentType = "application/pdf";
Response.BinaryWrite(b);
Response.Flush();
Response.End();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top