Google API Update File Visual Basic - vb.net

So...i am trying to use the update feature inside Visual Basic to update a files contents and metadata. Use the first piece of code to call it. However the code runs but does not update the file inside my drive and gives 0 errors. I am not sure what is wrong with the code since i have another piece of code which updates just the metadata just fine. Any help would be appreciated!
bob.updateFile(bob.service, "0Bzqp8R7eFke2aHZqZHdYZ2RpYjg", "listbox.txt", "Test #2", ".txt", "meme.txt ", True)
Public Function updateFile(service As DriveService, fileId As String, newTitle As String, newDescription As String, newMimeType As String, newFilename As String, newRevision As Boolean) As File
Try
' First retrieve the file from the API.
Dim file As File = service.Files.Get(fileId).Execute
' File's new metadata.
file.Title = newTitle
file.Description = newDescription
file.MimeType = newMimeType
' File's new content.
Dim byteArray() As Byte = System.IO.File.ReadAllBytes(newFilename)
Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream(byteArray)
'Send the request to the API.
Dim request As FilesResource.UpdateMediaUpload = service.Files.Update(file, fileId, stream, newMimeType)
request.NewRevision = newRevision
request.Upload()
Dim updatedFile As File = request.ResponseBody
Return updatedFile
stream.Close()
Catch e As Exception
MessageBox.Show(("An error occurred: " + e.Message))
End Try
End Function
====
This is the working code for the metadata
Public Function updateMetadata(ByVal service As DriveService, ByVal fileId As String, ByVal newTitle As String, ByVal newDescription As String, ByVal newMimeType As String, ByVal newRevision As Boolean) As File
Try
' First retrieve the file from the API.
Dim file As File = service.Files.Get(fileId).Execute
file.Title = newTitle
file.Description = newDescription
file.MimeType = newMimeType
' Update the file's metadata.
Dim request As FilesResource.UpdateRequest = service.Files.Update(file, fileId)
request.NewRevision = newRevision
Dim updatedFile As File = request.Execute
Return updatedFile
Catch e As Exception
MessageBox.Show(("An error occurred: " + e.Message))
Return Nothing
End Try
End Function

Hey guys thanks for the help!
Heres the working code, the issue was the mime type doesn't have to be changed!
bob.updateFile(bob.service, "0Bzqp8R7eFke2aHZqZHdYZ2RpYjg", "listbox.txt", "Test #2", ".txt", "meme.txt ", True)
Public Function updateFile(service As DriveService, fileId As String, newTitle As String, newDescription As String, newMimeType As String, newFilename As String, newRevision As Boolean) As File
Try
' First retrieve the file from the API.
Dim file As File = service.Files.Get(fileId).Execute
' File's new metadata.
file.Title = newTitle
file.Description = newDescription
'file.MimeType = newMimeType
' File's new content.
Dim byteArray() As Byte = System.IO.File.ReadAllBytes(newFilename)
Dim stream As System.IO.MemoryStream = New System.IO.MemoryStream(byteArray)
'Send the request to the API.
Dim request As FilesResource.UpdateMediaUpload = service.Files.Update(file, fileId, stream, newMimeType)
request.NewRevision = newRevision
request.Upload()
Dim updatedFile As File = request.ResponseBody
Return updatedFile
stream.Close()
Catch e As Exception
MessageBox.Show(("An error occurred: " + e.Message))
End Try
End Function

Related

Docusign download file from template which get illegal characters in file base64string format using Chilkat and rest api

I can get file from template which passing templateid and documentid, when retrun from api , i will get as base64string format, and when i try to convert as byte,
I get an error "Additional information: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters."
Here the code which i used to download file from template
Dim rest As New Chilkat.Rest
Dim success As Boolean
Dim bTls As Boolean = True
Dim port As Integer = 443
Dim bAutoReconnect As Boolean = True
success = rest.Connect("demo.docusign.net", port, bTls, bAutoReconnect)
If (success <> True) Then
Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
rest.AddHeader("X-DocuSign-Authentication", "{ ""Username"": ""DocuSign#example.com"", ""Password"":""DocuSign_password"", ""IntegratorKey"":""DocuSign_Integrator_Key"" }")
Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestNoBodySb("GET", "/restapi/v2.1/accounts/xxxx/templates/xxxx-xxxx-xxxx-xxxx-xxxx/documents/x", sbResponseBody)
If (success <> True) Then
Debug.WriteLine(rest.LastErrorText)
Exit Sub
End If
Dim respStatusCode As Integer = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
Debug.WriteLine("Response Status Code = " & respStatusCode)
Debug.WriteLine("Response Header:")
Debug.WriteLine(rest.ResponseHeader)
Debug.WriteLine("Response Body:")
Debug.WriteLine(sbResponseBody.GetAsString())
Exit Sub
End If
Dim jsonResponse As New Chilkat.JsonObject
jsonResponse.LoadSb(sbResponseBody)
Dim pdfBytes As Byte() = Convert.FromBase64String(sbResponseBody.ToString)
Regards,
Aravind
i changed my code from chilkat dll to Docusing dll 3.0.0 , using docusing dll i can download file from envelope, here i past my code , it will useful to some other developer.I am used .net framework code download file from file stream.
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 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"
}
Thanks to Inbar Gazit...
Thanks and Regards,
Aravind
Here is an example: https://www.example-code.com/vbnet/docusign_download_envelope_document.asp
Also see the other VB.NET DocuSign examples: https://www.example-code.com/vbnet/docusign.asp

How to download files from Docusign api using vb.net

How to download files once signed by all using vb.net. I manged to send envelope with template id.So i want to get back that file using envelope id, pls provide some sampe code to retrieve back files using vb.net.
Here code what i used in 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"
}
in that docSelect what need to pass ? i passed documetid, getting error.
Regards,
Aravind
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
You will need to get the nuget from here - https://www.nuget.org/packages/DocuSign.eSign.dll/ but version 5.0.0 won't work with the code above, use version 4.3
Update: adding this additional 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

Google Drive API v3 VB.NET Upload To Spesific Folder

Please Help, i'm trying to upload file to specific folder in my google drive using Vb.net. but, i'm googling for hours and not get working code. i cant sleep because this. here is my code:
Private Sub UploadFile(FilePath As String)
Try
If Service.ApplicationName <> "Google Drive VB Dot Net" Then CreateService()
Dim TheFile As New File()
TheFile.Name = "Database Sekretariat.accdb"
TheFile.Description = "A test document"
'TheFile.MimeType = "text/plain"
TheFile.Parents(0) = "1uMeTMRtvhm5_98udPmV8kp19aGtrmeQj"
Dim ByteArray As Byte() = System.IO.File.ReadAllBytes(FilePath)
Dim Stream As New System.IO.MemoryStream(ByteArray)
Dim UploadRequest As FilesResource.CreateMediaUpload = Service.Files.Create(TheFile, Stream, TheFile.MimeType)
UploadRequest.Upload()
Dim file As File = UploadRequest.ResponseBody
MsgBox("Upload Selesai " & file.Name & "")
Catch ex As Exception
MsgBox("Upload Gagal")
End Try
End Sub
use it in the following way, it is functional
First, i look for the ID folder
Public Sub SearchFolder()
IDFolderSave = String.Empty 'Global Variable
Try
Dim findrequest As FilesResource.ListRequest = Service.Files.List
Dim listFolder As Data.FileList = findrequest.Execute
For Each item As File In listFolder.Files
If item.MimeType = "application/vnd.google-apps.folder" Then
If item.Name = "NameFolder" Then
IDFolderSave = item.Id.ToString
Exit For
End If
End If
Next
Catch ex As Exception
Throw ex
End Try
'MsgBox("Folder id: " + idFolder)
End Sub
Second, upload file
Public Sub UploadFileInFolder()
Dim FilePath As String = String.Empty
FilePath = "C:\Icons\Loadding.gif"
Dim plist As List(Of String) = New List(Of String)
SearchFolder()
plist.Add(IDFolderSave) 'Set parent folder
If (System.IO.File.Exists(FilePath)) Then
Dim fileMetadata = New File() With {
.Name = "Test",
.Parents = plist
}
Dim request As FilesResource.CreateMediaUpload
Using stream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open)
request = Service.Files.Create(fileMetadata, stream, "application/octet-stream")
request.Fields = "id, parents"
request.Upload()
End Using
Dim file As File = request.ResponseBody
IDFileShared = file.Id
SharedFile()
MsgBox("File upload: " + file.Id)
Else
MsgBox("File does not exist: " + FilePath)
End If
End Sub
I hope it helps you

sending file telegram bot VB.NET

please help, I want to send a file (android.apk) from the bot telegram to the user, but the file the user received is not in the format (apk), how do I resolve this. I use vb.net and the Telegram.Bot library. this my code:
Public Async Function sendMessageFile(ByVal destID As String, ByVal Path As String, Optional ByVal
DescriptionFile As String = "") As Task
Try
Dim objReader As StreamReader
Dim objFS As FileStream
Dim errorf As String = ""
Try
If File.Exists(Path) Then
objFS = New FileStream(Path, FileMode.Open)
objReader = New StreamReader(objFS)
Await bott.SendDocumentAsync(destID, objFS, DescriptionFile)
objReader.Close()
objFS.Close()
objReader.Dispose()
objFS.Dispose()
objFS = Nothing
objReader = Nothing
Else
errorf = "File not found!"
End If
Catch ex As Exception
errorf = ex.Message
End Try
Catch e As Exception
log("sendMessageFile - " & e.Message)
End Try
End Function
'// this code sending file to user
Case "/download"
Await bott.SendChatActionAsync(ID, Telegram.Bot.Types.Enums.ChatAction.UploadDocument)
Const file As String = "C:\Resources\debug.apk"
Await sendMessageFile(ID, file, "TESTING")
'// screenshoot
https://prnt.sc/qf09sn

Using EchoSign API in VB.net

I'm trying to convert the sample C# code provided my echosign in VB.net for use within our applications. Specifically the SendDocument method.
Has anyone out there done this already?
The API is throwing back an error message "Fault: java.lang.NullPointerException" when ever i call it.
Here is the converted function:
Public Shared Function SendDocument(ByVal apiKey As String, ByVal file As Byte(), ByVal recipientEmailAddress As String, ByVal fileName As String, ByVal message As String, ByVal expireDays As Int32) As String
Try
Dim ES As EchoSignDocumentService13 = New EchoSignDocumentService13()
ES.Url = "https://secure.echosign.com/services/EchoSignDocumentService13"
Dim recipients(1) As String
recipients(0) = recipientEmailAddress
Dim localSenderInfo As com.echosign.secure.SenderInfo = Nothing
Dim echoFileInfo(1) As com.echosign.secure.FileInfo
echoFileInfo(0) = New com.echosign.secure.FileInfo()
With echoFileInfo(0)
.fileName = fileName
.mimeType = "application/msword"
.file = file
End With
Dim echoDocumentInfo As com.echosign.secure.DocumentCreationInfo = New com.echosign.secure.DocumentCreationInfo()
With echoDocumentInfo
.tos = recipients
.name = fileName
.message = message
.fileInfos = echoFileInfo
.signatureType = SignatureType.ESIGN
.signatureFlow = SignatureFlow.SENDER_SIGNATURE_NOT_REQUIRED
.daysUntilSigningDeadline = expireDays
End With
Dim echoKey() As DocumentKey
echoKey = ES.sendDocument(apiKey, localSenderInfo, echoDocumentInfo)
Return echoKey(0).documentKey.ToString()
Catch ex As Exception
Return "EchoError: " & ex.Message
End Try
End Function
Any help is most welcome
Thanks
Richard