0

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.

3
  • If you have access to the file then you can do System.IO.File.ReadAllBytes(path) to get the byte[]. Commented May 23, 2018 at 22:38
  • I don't have access to the file unless I download the file from Docusign which I am trying to do by getting byte[] and save db. Commented May 23, 2018 at 23:10
  • You should accept answer to your other qs as well so that it benefits others. Commented May 23, 2018 at 23:28

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.