Attach handler to an event: parameters
开发者_开发问答I have the following piece of code:
AddHandler sharepoint.UploadCompleted, AddressOf UploadEmailCompleted
I require it to work like so:
AddHandler sharepoint.UploadCompleted, AddressOf UploadEmailCompleted(message)
I fully appreciate this isn't possible, and after a little research, I think using a delegate may be the way forward. However I'm struggling to implement a solution that works.
Am I on the right track, or is what I'm attempting not possible?
What is message
intended to be? Is it the message that was sent, or an error message? If sharepoint.UploadedCompleted returns EventArgs, you can access these within your callback function. For example I have the following code for loading an email template within a service:
Public Function LoadEmailTemplate(ByVal template As String)
Dim path As String = AppDomain.CurrentDomain.BaseDirectory + "EmailTemplates\" + template
Return (File.ReadAllText(path))
End Function
Then within my client app, I just do:
Private Sub loadEmailTemplate_completed(ByVal sender As Object, ByVal e As MainServiceReference.LoadEmailTemplateCompletedEventArgs)
Dim body As String = e.Result
body = body.Replace("{CHEMICAL}", chemApp.Chemical.tradeName)
body = body.Replace("{REQUESTEDBY}", chemApp.requestedBy)
body = body.Replace("{FACILITY}", chemApp.facilityPath)
body = body.Replace("{ID}", chemApp.ID)
clientMain.SendMailAsync(toAddress, fromAddress, subject, body)
End Sub
I can then access the return value via the LoadEmailTemplateCompletedEventArgs
. Can you do something similar with sharepoint.uploadcompleted? i.e configure it to return a value, then access it via EventArgs?
Oh, for reference, the event handler is just:
AddHandler clientMain.LoadEmailTemplateCompleted, AddressOf loadEmailTemplate_completed
精彩评论