Initiates an async download of the attachment. When the download is complete, the DownloadAttachmentCompleted event will fire and its event arguments will contain the attachment. You can obtain the parameters from the MessageReceived event's arguments AttachmentInfo.
Namespace:
Linxter.SDKAssembly: Linxter.SDK (in Linxter.SDK.dll) Version: 1.5.0.0 (1.5.0.0)
Syntax
| C# |
|---|
void DownloadAttachmentAsync( AttachmentInfo attachInfo ) |
| Visual Basic (Declaration) |
|---|
Sub DownloadAttachmentAsync ( _ attachInfo As AttachmentInfo _ ) |
Parameters
- attachInfo
- Type: Linxter.Common.Entities..::.AttachmentInfo
The AttachmentInfo data structure returned with a MessageReceived event that you want to download.
Examples
ILinxterMessaging m_messageObject; public void DownloadAttachmentAsyncExample() { // Set up Linxter m_messageObject = new LinxterSDK(); // Hook MessageReceived and DownloadAttachmentCompleted events m_messageObject.MessageReceived += new Action<Linxter.SDK.EventArgs.MessageReceivedEventArgs>(OnMessageReceivedA); m_messageObject.DownloadAttachmentCompleted += new Action<Linxter.SDK.EventArgs.DownloadAttachmentCompletedEventArgs>(OnDownloadAttachmentCompleted); } void OnMessageReceivedA(Linxter.SDK.EventArgs.MessageReceivedEventArgs obj) { // Notify user and save attachment(s) MessageBox.Show(string.Format("New message received:\n{0}", obj.Body)); foreach (AttachmentInfo item in obj.Attachments) { // Initiate download of each attachment m_messageObject.DownloadAttachmentAsync(item); } } void OnDownloadAttachmentCompleted(Linxter.SDK.EventArgs.DownloadAttachmentCompletedEventArgs obj) { if (obj.Cancelled) // Check to see if there has been a problem { MessageBox.Show(string.Format("Download of message attachment cancelled, Linxter returned the following information:\n{0}", obj.Error.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else // Otherwise just save the file in C:\MessageAttachments { string filename = Path.Combine("C:\\MessageAttachments", Path.GetFileName(obj.Attachment.FileName)); try { System.IO.File.WriteAllBytes(filename, obj.Attachment.Data); } catch (IOException ex) { MessageBox.Show(string.Format("Save attachment '{0}' failed. Error message: {1}", filename, ex.Message), "Cannot save", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
Private m_messageObject As ILinxterMessaging Public Sub DownloadAttachmentAsyncExample() ' Set up Linxter m_messageObject = New LinxterSDK() ' Hook MessageReceived and DownloadAttachmentCompleted events AddHandler m_messageObject.MessageReceived, AddressOf OnMessageReceivedA AddHandler m_messageObject.DownloadAttachmentCompleted, AddressOf OnDownloadAttachmentCompleted End Sub Private Sub OnMessageReceivedA(ByVal obj As Linxter.SDK.EventArgs.MessageReceivedEventArgs) ' Notify user and save attachment(s) MessageBox.Show(String.Format("New message received:" & vbLf & "{0}", obj.Body)) For Each item As AttachmentInfo In obj.Attachments ' Initiate download of each attachment m_messageObject.DownloadAttachmentAsync(item) Next item End Sub Private Sub OnDownloadAttachmentCompleted(ByVal obj As Linxter.SDK.EventArgs.DownloadAttachmentCompletedEventArgs) If obj.Cancelled Then ' Check to see if there has been a problem MessageBox.Show(String.Format("Download of message attachment cancelled, Linxter returned the following information:" & vbLf & "{0}", obj.Error.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Else ' Otherwise just save the file in C:\MessageAttachments Dim filename As String = Path.Combine("C:\MessageAttachments", Path.GetFileName(obj.Attachment.FileName)) Try System.IO.File.WriteAllBytes(filename, obj.Attachment.Data) Catch ex As IOException MessageBox.Show(String.Format("Save attachment '{0}' failed. Error message: {1}", filename, ex.Message), "Cannot save", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If End Sub