【发布时间】:2019-02-05 10:53:43
【问题描述】:
我已经创建了 webform aspx 文件,并且我有一个生成 pdf 然后上传到我的表单的按钮。当我单击提交按钮时,需要在 vb 文件中调用一个函数,例如 DocuSign 的 CreateEnvelpoeAPI。无论如何,如何通过aspx页面调用函数?
//form.aspx.vb
Protected Sub btSubmit_Click(sender As Object, e As EventArgs) Handles btSubmit.Click
Response.Redirect("CreateEnvelopeAPI.vb") // I expecte to call function n in here.
End Sub
// CreateEnvelopeAPI.vb
Public Class CreateEnvelopeAPI
Public Function Init() As String
Dim username As String = ""
Dim password As String = ""
Dim integratorKey As String = ""
' initialize client for desired environment (for production change to www)
Dim apiClient As New ApiClient("https://demo.docusign.net/restapi")
Configuration.[Default].ApiClient = apiClient
' configure 'X-DocuSign-Authentication' header
Dim authHeader As String = (Convert.ToString((Convert.ToString((Convert.ToString("{""Username"":""") & username) + """, ""Password"":""") & password) + """, ""IntegratorKey"":""") & integratorKey) + """}"
Configuration.[Default].AddDefaultHeader("X-DocuSign-Authentication", authHeader)
' we will retrieve this from the login API call
Dim accountId As String = Nothing
'''//////////////////////////////////////////////////////////////
' STEP 1: LOGIN API
'''//////////////////////////////////////////////////////////////
' login call is available in the authentication api
Dim authApi As New AuthenticationApi()
Dim loginInfo As LoginInformation = authApi.Login()
' parse the first account ID that is returned (user might belong to multiple accounts)
accountId = loginInfo.LoginAccounts(0).AccountId
' Update ApiClient with the new base url from login call
apiClient = New ApiClient(loginInfo.LoginAccounts(0).BaseUrl)
Return accountId
End Function
Public Sub CreateEnvelopeAPI()
Dim accountId As String = Init()
Dim fileBytes As Byte() = File.ReadAllBytes("Invoice.pdf")
Dim envDef = New EnvelopeDefinition()
envDef.EmailSubject = "[DocuSign C# SDK] - Custom Fields"
envDef.Status = "sent"
envDef.CustomFields = New CustomFields()
Dim textCustomField = New TextCustomField()
textCustomField.Name = "TransactionId"
textCustomField.Value = "KTI456"
Dim textCustomFields = New List(Of TextCustomField)()
textCustomFields.Add(textCustomField)
envDef.CustomFields.TextCustomFields = textCustomFields
' Add a recipient to sign the documeent
Dim signer As New Signer()
signer.Email = ""
signer.Name = ""
signer.RecipientId = "1"
signer.Tabs = New Tabs()
signer.Tabs.SignHereTabs = New List(Of SignHere)()
Dim signHereTab = New SignHere()
signHereTab.DocumentId = "1"
signHereTab.PageNumber = "1"
signHereTab.XPosition = "100"
signHereTab.YPosition = "100"
signer.Tabs.SignHereTabs.Add(signHereTab)
envDef.Recipients = New Recipients()
envDef.Recipients.Signers = New List(Of Signer)()
envDef.Recipients.Signers.Add(signer)
' Add a document to the envelope
Dim doc As New Document()
doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes)
doc.Name = "Invoice.pdf"
doc.DocumentId = "1"
envDef.Documents = New List(Of Document)()
envDef.Documents.Add(doc)
Dim envelopesApi As New EnvelopesApi()
Dim envelopeSummary As EnvelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef)
Console.WriteLine(envelopeSummary)
End Sub
End Class
【问题讨论】:
标签: asp.net vb.net webforms docusignapi