title: Request Signature Docusign Rest API vb.net
body: <p>am trying to use the DocuSign .Net Client to request a signature on a Document I am creating dynamically. So far, I have been able to change the example to vb.net and it works (<a href="https://github.com/docusign/DocuSign-.NET-Client/blob/master/Examples.cs" rel="nofollow">Exmaple CS</a>). I was converting the "Walkthrough #4 - Request Signature on Document", about 1/2 way down the code. Now I am trying to use the Envelope.Document I've seen in other examples, such as, <a href="https://www.docusign.com/p/APIGuide/Content/Sending%20Group/Create%20and%20Send.htm" rel="nofollow">DocuSign example</a>. But it seems .Document is not part of Envelope, even thought the rest of the code in both examples translates to vb.</p>
  
  <p>My other option is to use the Envelope.AddDocument but I can't seem to figure out what it's expecting. I am supposed to pass fileBytes() as Byte, fileName as String, and index As Integer. I've tried a couple different methods to get the fileBytes but keep getting an error about Invalid_Content_Type Content type is not supported.</p>
  
  <p>Here is the code I've been trying. Any help on how to add a Document to an Envelope would be appreciated. Ultimately I want to be able to add multiple documents to the one envelope. I can get the env.Create(docPath) to work, but that is not helpful.
  Thank you in advance for any help you can offer.</p>
  
  <pre><code>Public Function RequestEsignature(email As String, rName As String, docPath As String, strSubject As String) As String
      main()
      Dim AccountEmail = My.Settings.docusignUserName
      Dim AccountPassword = My.Settings.docusignPassword
      Dim RecipientEmail = email
      Dim RecipientName = rName
      Dim documentPath = docPath
      Dim msgString As String
      Dim acct As Account = New Account()
      acct.Email = AccountEmail
      acct.Password = AccountPassword
  
      Dim result As Boolean = acct.Login()
      If Not result Then
          msgString = String.Format("There was an error logging in to DocuSign fo user {0}.\nError Code:  {1}\nMessage:  {2}", acct.Email, acct.RestError.errorCode, acct.RestError.message)
          MsgBox(msgString)
          Return Nothing
      End If
  
      Dim env As Envelope = New Envelope
      env.Login = acct
  
      env.Recipients = New Recipients()
      Dim signer(0) As Signer
      signer(0) = New Signer()
      signer(0).email = email
      signer(0).name = RecipientName
      signer(0).routingOrder = "1"
      signer(0).recipientId = "1"
      env.Recipients.signers = signer
  
      Dim envDocs = New Document()
      envDocs.documentId = "1"
      envDocs.name = "Test Document"
      envDocs.uri = docPath
  
      'Dim fileBytes As Byte()
      'Dim fileBytes = getByteArrayII(documentPath)
      'Dim oFile As FileInfo
      'oFile = New FileInfo(documentPath)
      'Dim oFileStream As FileStream = oFile.OpenRead()
      'Dim lBytes As Long = oFileStream.Length
  
      'If lBytes &gt; 0 Then
      '    Dim fileData(lBytes - 1) As Byte
      '    oFileStream.Read(fileData, 0, lBytes)
      'If Not env.AddDocument(fileBytes, documentPath, 0) Then
      '    msgString = String.Format("The was an Error adding the Document." &amp; vbCrLf &amp; "Error Code:  {0} " &amp; vbCrLf &amp; "Message:  {1}", env.RestError.errorCode, env.RestError.message)
      '    MsgBox(msgString)
      '    Return Nothing
      'Else
      '    MsgBox("Doc Successfully Added")
      'End If
      'oFileStream.Close()
      'End If
  
  
      env.Status = "sent"
      env.EmailSubject = strSubject
      result = env.Create()
  
      If Not result Then
          If Not IsNothing(env.RestError) Then
              msgString = String.Format("Error Code:  {0}\nMessage:  {1}", env.RestError.errorCode, env.RestError.message)
              MsgBox(msgString)
              Return Nothing
          Else
              MsgBox("There was a nondescript error while processing this request. \nPLease verify all information is correct before trying again.")
              Return Nothing
          End If
      Else
          Return env.EnvelopeId
      End If
  End Function
  
  Private Function getByteArray(fileName As String) As Byte()
      Dim fInfo As New FileInfo(fileName)
      Dim numBytes As Long = fInfo.Length
      Dim fStream As New FileStream(fileName, FileMode.Open, FileAccess.Read)
      Dim br As New BinaryReader(fStream)
      Dim data As Byte() = br.ReadBytes(CInt(numBytes))
      br.Close()
      fStream.Close()
      Return data
  End Function
  
  Private Function getByteArrayII(ByVal fileName As String) As Byte()
      Dim tempByte() As Byte = Nothing
      If String.IsNullOrEmpty(fileName) Then
          Throw New ArgumentNullException("FileName Not Provided")
          Return Nothing
      End If
      Try
          Dim fileInfo As New FileInfo(fileName)
          Dim numBytes As Long = fileInfo.Length
          Dim fStream As New FileStream(fileName, FileMode.Open, FileAccess.Read)
          Dim binaryReader As New BinaryReader(fStream)
          tempByte = binaryReader.ReadBytes(Convert.ToInt32(numBytes))
          fileInfo = Nothing
          numBytes = 0
          fStream.Close()
          fStream.Dispose()
          Return tempByte
      Catch ex As Exception
          Return Nothing
      End Try
  End Function
  </code></pre>
  
  <p>HISTORY
  I am new to vb.net and programming. Thus far I have been able to make a program that allows users to enter client information with the forms being changed based on certain selections. We have a system that uses our SQL data to do mail merges in Word and then send a PDF for esignature to the client through DocuSign. We are using a SQL backend and a vb.net front end.</p>
  
  <p>Lastly, I have been looking for an answer over the weekend and am now reaching out for help. I have searched google for every possible term(s) I can think to include/exclude. If I am asking publicly that truly means I have exhausted every resource I have. Please do not post links to any DocuSign Documentation as I have already visited all those sites. Thank you.</p>