/// <summary> /// Creates an item or file attachment on an item in the server store. /// </summary> /// <param name="createAttachmentRequest">A CreateAttachmentType complex type specifies a request message to attach an item or file to a specified item in the server database. </param> /// <returns>A CreateAttachmentResponseType complex type specifies the response message that is returned by the CreateAttachment operation. </returns> public CreateAttachmentResponseType CreateAttachment(CreateAttachmentType createAttachmentRequest) { CreateAttachmentResponseType createAttachmentResponse = this.exchangeServiceBinding.CreateAttachment(createAttachmentRequest); Site.Assert.IsNotNull(createAttachmentResponse, "If the operation is successful, the response should not be null."); this.VerifySoapVersion(); this.VerifyTransportType(); this.VerifyServerVersionInfo(this.exchangeServiceBinding.IsSchemaValidated); if (createAttachmentResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success) { this.VerifyCreateAttachmentResponse(createAttachmentResponse, this.exchangeServiceBinding.IsSchemaValidated); } return createAttachmentResponse; }
/// <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 void CreateAttachmentAsync(CreateAttachmentType CreateAttachment1) { this.CreateAttachmentAsync(CreateAttachment1, null); }
/// <remarks/> public System.IAsyncResult BeginCreateAttachment(CreateAttachmentType CreateAttachment1, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("CreateAttachment", new object[] { CreateAttachment1}, callback, asyncState); }
/// <summary> /// Creates an item or file attachment on an item. /// </summary> /// <param name="parentItemId">Identifies the parent item in the server store that contains the attachment.</param> /// <param name="attachmentsType">Attachment type.</param> /// <returns>A response message for "CreateAttachment" operation.</returns> protected CreateAttachmentResponseType CallCreateAttachmentOperation(string parentItemId, params AttachmentTypeValue[] attachmentsType) { // Configure attachments. int attachmentCount = attachmentsType.Length; this.Attachments = new AttachmentType[attachmentCount]; for (int attachmentIndex = 0; attachmentIndex < attachmentCount; attachmentIndex++) { AttachmentType attachment = null; if (attachmentsType[attachmentIndex] == AttachmentTypeValue.FileAttachment) { FileAttachmentType fileAttachment = new FileAttachmentType() { ContentLocation = @"http://www.contoso.com/xyz.abc", Name = "attach.jpg", // Ensure content id is unique. ContentId = Guid.NewGuid().ToString(), ContentType = "image/jpeg", Content = Convert.FromBase64String("/9j/4AAQSkZJRgABAQEAYABgAAD/7AARRHVja3kAAQAEAAAARgAA/9sAQwACAQECAQECAgICAgICAgMFAwMDAwMGBAQDBQcGBwcHBgcHCAkLCQgICggHBwoNCgoLDAwMDAcJDg8NDA4LDAwM/9sAQwECAgIDAwMGAwMGDAgHCAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM/8AAEQgADAAUAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A5j9hnXPH/gy003RdI+KejWVjciO7muPF86y2GiWFu3nahceUJUyEtfOcKroplMZeSJAxH1j+2p8f9L8TfBTw1qvwo8YSSWGr6FB4p1bStWsLi01TVPDl4ZLe21CwkeOJ9yXf2cSQlCfKukdjDvhM34beLf2n/G3wz+B2g+ItA1qbS9Y0bxBm1uIlDFA9vPG6kNkFWQlSp4welZfxG/4K1fHj9ozQj4T8V+N73U9J1u7e7uxLmWU+YYWaGJ5Cxt7fzLeF/s8Hlxbox8mABXNQjVjQnQlVk+zurrRbWSXnbbuedTyvD0ISoQvZ333WnyPqLxp8PG8feIrjU5dG8O60ZWMYuDeW1tjyyUKeWzALtZWGFG3Oe+aK/OP4ja3c+CfiZ4m07TJTbWdvq90iIQJSAsrKMs+WJwo6miuFZRbT2svvX+QoZTQirXf4f5H/2Q==") }; attachment = fileAttachment; } else if (attachmentsType[attachmentIndex] == AttachmentTypeValue.ReferenceAttachment) { ReferenceAttachmentType referenceAttachment = new ReferenceAttachmentType() { AttachLongPathName = @"http://www.contoso.com/xyz.abc", ProviderType = "abc", ProviderEndpointUrl = @"http://www.contoso.com", AttachmentPreviewUrl = @"http://www.contoso.com/Preview.abc", AttachmentThumbnailUrl = @"http://www.contoso.com/Thumbnail.abc", ContentLocation = @"http://www.contoso.com/xyz.abc", Name = "RefAttachment", ContentId = Guid.NewGuid().ToString(), ContentType = "image/jpeg", }; attachment = referenceAttachment; } else { ItemAttachmentType itemAttachment = new ItemAttachmentType() { ContentLocation = @"http://www.contoso.com/xyz.abc", Name = "ItemName", // Ensure content id is unique. ContentId = Guid.NewGuid().ToString(), ContentType = "image/jpeg", }; switch (attachmentsType[attachmentIndex]) { case AttachmentTypeValue.ItemAttachment: itemAttachment.Item = new ItemType(); break; case AttachmentTypeValue.MessageAttachment: itemAttachment.Item = new MessageType() { Body = new BodyType() { BodyType1 = BodyTypeType.HTML, Value = "<html><body><b>Bold</b><script>alert('Alert!');</script></body></html>" }, }; break; case AttachmentTypeValue.CalendarAttachment: itemAttachment.Item = new CalendarItemType() { StartSpecified = true, EndSpecified = true }; break; case AttachmentTypeValue.ContactAttachment: itemAttachment.Item = new ContactItemType(); break; case AttachmentTypeValue.PostAttachment: itemAttachment.Item = new PostItemType(); break; case AttachmentTypeValue.TaskAttachment: itemAttachment.Item = new TaskType(); break; case AttachmentTypeValue.MeetingMessageAttachemnt: itemAttachment.Item = new MeetingMessageType(); break; case AttachmentTypeValue.MeetingRequestAttachment: itemAttachment.Item = new MeetingRequestMessageType(); break; case AttachmentTypeValue.MeetingResponseAttachment: itemAttachment.Item = new MeetingResponseMessageType(); break; case AttachmentTypeValue.MeetingCancellationAttachment: itemAttachment.Item = new MeetingCancellationMessageType(); break; case AttachmentTypeValue.PersonAttachment: itemAttachment.Item = new AbchPersonItemType() { AntiLinkInfo = "", PersonId = Guid.NewGuid().ToString(), ContactHandles = new AbchPersonContactHandle[] { new AbchPersonContactHandle(), }, ContactCategories = new string[] { "test category" }, }; break; } attachment = itemAttachment; } this.Attachments[attachmentIndex] = attachment; } CreateAttachmentType createAttachmentRequest = new CreateAttachmentType() { ParentItemId = new ItemIdType() { Id = parentItemId }, Attachments = this.Attachments }; return this.ATTAdapter.CreateAttachment(createAttachmentRequest); }