/// <remarks/>
 public void CreateAttachmentAsync(CreateAttachmentType CreateAttachment1, object userState)
 {
     if ((this.CreateAttachmentOperationCompleted == null))
     {
         this.CreateAttachmentOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateAttachmentOperationCompleted);
     }
     this.InvokeAsync("CreateAttachment", new object[] {
             CreateAttachment1}, this.CreateAttachmentOperationCompleted, userState);
 }
 /// <remarks/>
 public System.IAsyncResult BeginCreateAttachment(CreateAttachmentType CreateAttachment1, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("CreateAttachment", new object[] {
             CreateAttachment1}, callback, asyncState);
 }
 /// <remarks/>
 public void CreateAttachmentAsync(CreateAttachmentType CreateAttachment1)
 {
     this.CreateAttachmentAsync(CreateAttachment1, null);
 }
Example #4
0
        /// <summary>
        /// Saves all attachments belonging to a specific message. This method can only be called after the message
        /// has been saved in exchange.
        /// </summary>
        /// <param name="messageId"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public IEnumerable<ItemIdType> SaveAttachments(ItemIdType messageId, ChannelMessage message)
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            // Create add attachment request.
            var attachementRequest = new CreateAttachmentType();
            attachementRequest.ParentItemId = messageId;
            attachementRequest.Attachments = new AttachmentType[message.Attachments.Count];

            for (int i = 0; i < message.Attachments.Count; i++)
            {
                var channelAttachment = message.Attachments[i];
                var exchAttachment = new FileAttachmentType();

                exchAttachment.Name = channelAttachment.Filename;
                exchAttachment.ContentType = MimeHelper.GetMimeType(channelAttachment.Filename);
                exchAttachment.Content = channelAttachment.ContentStream.GetBytes();

                attachementRequest.Attachments[i] = exchAttachment;

                var saveAttachmentResponse = binding.CreateAttachment(attachementRequest);

                // Determine whether the request was a success.
                if (saveAttachmentResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
                    throw new Exception(saveAttachmentResponse.ResponseMessages.Items[0].MessageText);

                AttachmentIdType attachmentId = ((AttachmentInfoResponseMessageType)saveAttachmentResponse.ResponseMessages.Items[0]).Attachments[0].AttachmentId;

                yield return new ItemIdType { ChangeKey = attachmentId.RootItemChangeKey, Id = attachmentId.RootItemId };
            }
        }