Edit

Share via


AttachmentType Class

Definition

The AttachmentType class represents an attachment.

public ref class AttachmentType
public class AttachmentType
Public Class AttachmentType
Inheritance
AttachmentType
Derived

Examples

The following example shows you the use of the FileAttachmentType and the ItemAttachmentType. Both of these types are derived from the AttachmentType class. These two types are added to the Attachments property of the CreateAttachmentType class. This example also shows you the use of the AttachmentType in the AttachmentInfoResponseMessageType object.

static void CreateAttachment(ExchangeServiceBinding esb)
{
    // Create item attachment.
    MessageType message = new MessageType();
    message.Subject = "Example subject";
    message.Importance = ImportanceChoicesType.Low;
    message.ImportanceSpecified = true;

    ItemAttachmentType itemAttach = new ItemAttachmentType();
    itemAttach.Name = "Message Attachment Example";
    itemAttach.Item = message;

    // Create file attachment.
    FileAttachmentType fileAttach = new FileAttachmentType();
    fileAttach.Name = "filename.txt";
    fileAttach.ContentType = "text/plain";

    byte[] content;
    using (FileStream fileStream = new FileStream("C:\\cas.txt",
        FileMode.Open, FileAccess.Read))
    {
        content = new byte[fileStream.Length];
        fileStream.Read(content, 0, content.Length);
    }

    fileAttach.Content = content;

    // Create the CreateAttachment request.
    CreateAttachmentTypereqCreateAttach = new CreateAttachmentType();

    // Identify the item that will have the attachments.
    ItemIdType item = new ItemIdType();
    item.Id = "AAAlAE1BQG1h";
    item.ChangeKey = "DwAAABYAAA"; 

    // Add the parent item to the request.
    reqCreateAttach.ParentItemId = item;

    // Add attachments to the request.
    reqCreateAttach.Attachments = new AttachmentType[2];
    reqCreateAttach.Attachments[0] = itemAttach;
    reqCreateAttach.Attachments[1] = fileAttach;

    try
    {
        CreateAttachmentResponseType resp = esb.CreateAttachment(reqCreateAttach);
        ArrayOfResponseMessagesType aorit = resp.ResponseMessages;
        ResponseMessageType[] rmta = aorit.Items;

        foreach (ResponseMessageType rmt in rmta)
        {
            if (rmt.ResponseClass == ResponseClassType.Success)
            {
                AttachmentInfoResponseMessageType airmt = rmt as AttachmentInfoResponseMessageType;
                foreach (AttachmentType atch in airmt.Attachments)
                {
                    if (atch is ItemAttachmentType)
                    {
                        Console.WriteLine("Created item attachment");
                    }
                    else if (atch is FileAttachmentType)
                    {
                        Console.WriteLine("Created file attachment");
                    }
                    else
                    {
                        throw new Exception("Unknown attachment");
                    }
                }
            }
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

Remarks

The AttachmentType class can represent either a file or an item attachment. The AttachmentType class is the base type for the FileAttachmentType and the ItemAttachmentType classes.

Constructors

AttachmentType()

The AttachmentType constructor initializes a new instance of the AttachmentType class.

Properties

AttachmentId

The AttachmentId property gets or sets the attachment identifier. This property is read/write.

ContentId

The ContentId property gets or sets the attachment content identifier. This property is read/write.

ContentLocation

The ContentLocation property gets or sets the Uniform Resource Identifier (URI) that corresponds to the location of the content of the attachment. This property is read-only.

ContentType

The ContentType property gets or sets a value that describes the Multipurpose Internet Mail Extensions (MIME) type of the attachment content.

IsInline

The IsInline property gets or sets a Boolean value that specifies whether the attachment appears inline within an item.

IsInlineSpecified

The IsInlineSpecified property gets a Boolean value that specifies whether the IsInline property is serialized into the SOAP request. This property is read-only.

LastModifiedTime

The LastModifiedTime property gets a DateTime value that specifies when the attachment was last modified.

LastModifiedTimeSpecified

The LastModifiedTimeSpecified property gets a Boolean value that specifies whether the LastModifiedTime property is serialized into the SOAP request. This property is read-only.

Name

The Name property gets or sets the name of the attachment.

Size

The Size property gets or sets an integer value that represents the size in bytes of an attachment.

SizeSpecified

The SizeSpecified property gets a Boolean value that specifies whether the SizeSpecified property is serialized into the SOAP request. This property is read-only.

Applies to