Noeleven
Noeleven

Reputation: 5

Docusign API to get byte[] for document in envelope

I am developing MVC web application with c# utilizing Docusign API. This is REST API that Docusign provides.

GET /v2/accounts/{accountId}/envelopes/{envelopeId}/documents/{documentId}

When I call this HTTP request, Windows pops up and ask user to select the folder and set name of file to save the document in PDF format.

I would like to get byte[] value for the document so that I can save it to BLOB in db.

Is there any way to call this Docusign API to get byte[]? I am new to programming and any help or advise will help.

Thank you.

Upvotes: 0

Views: 836

Answers (1)

Amit K Bist
Amit K Bist

Reputation: 6808

Code should look like below:

// GetDocument() API call returns a MemoryStream

MemoryStream docStream = (MemoryStream)envelopesApi.GetDocument(accountId, envelopeId, documentId);

Above method uses DocuSign's C# SDK , check LegacyListDocumentsAndDownloadTest method.

To Write MemoryStream to Database:

public static int databaseFilePut(MemoryStream fileToPut) {
        int varID = 0;
        byte[] file = fileToPut.ToArray();
        const string preparedCommand = @"
                    INSERT INTO [dbo].[Raporty]
                               ([RaportPlik])
                         VALUES
                               (@File)
                        SELECT [RaportID] FROM [dbo].[Raporty]
            WHERE [RaportID] = SCOPE_IDENTITY()
                    ";
        using (var varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetails))
        using (var sqlWrite = new SqlCommand(preparedCommand, varConnection)) {
            sqlWrite.Parameters.Add("@File", SqlDbType.VarBinary, file.Length).Value = file;

            using (var sqlWriteQuery = sqlWrite.ExecuteReader())
                while (sqlWriteQuery != null && sqlWriteQuery.Read()) {
                    varID = sqlWriteQuery["RaportID"] is int ? (int) sqlWriteQuery["RaportID"] : 0;
                }
        }
        return varID;
    }

or you can also check

How to Store and Read Byte Array and 2579373

Upvotes: 2

Related Questions