如何使用 vb.net 从 Docusign api 下载文件

How to download files from Docusign api using vb.net

如何下载所有使用 vb.net 签名的文件。我设法发送带有模板 id.So 的信封 我想使用信封 ID 取回该文件,请提供一些示例代码以使用 vb.net.

取回文件

这里是我在vb.net

中使用的代码
Private Function DoWnload(ByVal accessToken As String, ByVal basePath As String, ByVal accountId As String, ByVal envelopeId As String, ByVal documents As List(Of EnvelopeDocItem), ByVal docSelect As String) As String
    Dim config = New Configuration(New ApiClient(basePath))
    config.AddDefaultHeader("Authorization", "Bearer " & accessToken)
    Dim envelopesApi As EnvelopesApi = New EnvelopesApi(config)
    Dim results As System.IO.Stream = envelopesApi.GetDocument(accountId, envelopeId, docSelect)
    Dim docItem As EnvelopeDocItem = documents.FirstOrDefault(Function(d) docSelect.Equals(d.DocumentId))
    Dim docName As String = docItem.Name
    Dim hasPDFsuffix As Boolean = docName.ToUpper().EndsWith(".PDF")
    Dim pdfFile As Boolean = hasPDFsuffix
    Dim docType As String = docItem.Type

    If ("content".Equals(docType) OrElse "summary".Equals(docType)) AndAlso Not hasPDFsuffix Then
        docName += ".pdf"
        pdfFile = True
    End If

    If "zip".Equals(docType) Then
        docName += ".zip"
    End If

    Dim mimetype As String

    If pdfFile Then
        mimetype = "application/pdf"
    ElseIf "zip".Equals(docType) Then
        mimetype = "application/zip"
    Else
        mimetype = "application/octet-stream"
    End If
    ''Dim f1 As FileStream = New FileStream("sample.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite)
    '  Return File(results, mimetype, docName)

    Dim bytesRead As Integer
    Dim buffer(4096) As Byte

    Using outFile As New System.IO.FileStream("C:\File.pdf", IO.FileMode.Create, IO.FileAccess.Write)
        Do
            bytesRead = results.Read(buffer, 0, buffer.Length)
            If bytesRead > 0 Then
                outFile.Write(buffer, 0, bytesRead)
            End If
        Loop While bytesRead > 0
    End Using
    Return ""

End Function



   Dim envelopeDocItems As List(Of EnvelopeDocItem) = New List(Of EnvelopeDocItem) From {
New EnvelopeDocItem With {
    .Name = "Combined",
    .Type = "content",
    .DocumentId = "combined"
},
New EnvelopeDocItem With {
    .Name = "Zip archive",
    .Type = "zip",
    .DocumentId = "archive"
}

在该文档中选择需要传递的内容?我通过了 documetid,出现错误。

此致, 亚拉文

Private Function DoWork(ByVal accessToken As String, ByVal basePath As String, ByVal accountId As String, ByVal envelopeId As String, ByVal documents As List(Of EnvelopeDocItem), ByVal docSelect As String) As FileStreamResult
    Dim config = New Configuration(New ApiClient(basePath))
    config.AddDefaultHeader("Authorization", "Bearer " & accessToken)
    Dim envelopesApi As EnvelopesApi = New EnvelopesApi(config)
    Dim results As System.IO.Stream = envelopesApi.GetDocument(accountId, envelopeId, docSelect)
    Dim docItem As EnvelopeDocItem = documents.FirstOrDefault(Function(d) docSelect.Equals(d.DocumentId))
    Dim docName As String = docItem.Name
    Dim hasPDFsuffix As Boolean = docName.ToUpper().EndsWith(".PDF")
    Dim pdfFile As Boolean = hasPDFsuffix
    Dim docType As String = docItem.Type

    If ("content".Equals(docType) OrElse "summary".Equals(docType)) AndAlso Not hasPDFsuffix Then
        docName += ".pdf"
        pdfFile = True
    End If

    If "zip".Equals(docType) Then
        docName += ".zip"
    End If

    Dim mimetype As String

    If pdfFile Then
        mimetype = "application/pdf"
    ElseIf "zip".Equals(docType) Then
        mimetype = "application/zip"
    Else
        mimetype = "application/octet-stream"
    End If

    Return File(results, mimetype, docName)
End Function

您需要从这里获取 nuget - https://www.nuget.org/packages/DocuSign.eSign.dll/ 但是 5.0.0 版不能使用上面的代码,请使用 4.3 版

更新:添加这个额外的class:

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Threading.Tasks

Namespace Models
    Public Class EnvelopeDocItem
        Public Property Name As String
        Public Property Type As String
        Public Property DocumentId As String
    End Class
End Namespace