Compartir a través de


AttachmentType Class

The AttachmentType class represents an attachment.

Namespace: ExchangeWebServices
Assembly: EWS (in ews.dll)

Syntax

'Declaration
<SerializableAttribute> _
<XmlIncludeAttribute(GetType(ItemAttachmentType))> _
<DesignerCategoryAttribute("code")> _
<XmlTypeAttribute(Namespace:="https://schemas.microsoft.com/exchange/services/2006/types")> _
<GeneratedCodeAttribute("wsdl", "2.0.50727.42")> _
<DebuggerStepThroughAttribute> _
<XmlIncludeAttribute(GetType(FileAttachmentType))> _
Public Class AttachmentType
[SerializableAttribute] 
[XmlIncludeAttribute(typeof(ItemAttachmentType))] 
[DesignerCategoryAttribute("code")] 
[XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/types")] 
[GeneratedCodeAttribute("wsdl", "2.0.50727.42")] 
[DebuggerStepThroughAttribute] 
[XmlIncludeAttribute(typeof(FileAttachmentType))] 
public class AttachmentType
[SerializableAttribute] 
[XmlIncludeAttribute(typeof(ItemAttachmentType))] 
[DesignerCategoryAttribute(L"code")] 
[XmlTypeAttribute(Namespace=L"https://schemas.microsoft.com/exchange/services/2006/types")] 
[GeneratedCodeAttribute(L"wsdl", L"2.0.50727.42")] 
[DebuggerStepThroughAttribute] 
[XmlIncludeAttribute(typeof(FileAttachmentType))] 
public ref class AttachmentType
/** @attribute SerializableAttribute() */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.ItemAttachmentType) */ 
/** @attribute DesignerCategoryAttribute("code") */ 
/** @attribute XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/types") */ 
/** @attribute GeneratedCodeAttribute("wsdl", "2.0.50727.42") */ 
/** @attribute DebuggerStepThroughAttribute() */ 
/** @attribute XmlIncludeAttribute(ExchangeWebServices.FileAttachmentType) */ 
public class AttachmentType
SerializableAttribute 
XmlIncludeAttribute(ExchangeWebServices.ItemAttachmentType) 
DesignerCategoryAttribute("code") 
XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/types") 
GeneratedCodeAttribute("wsdl", "2.0.50727.42") 
DebuggerStepThroughAttribute 
XmlIncludeAttribute(ExchangeWebServices.FileAttachmentType) 
public class AttachmentType

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.

Inheritance Hierarchy

System.Object
  ExchangeWebServices.AttachmentType
     ExchangeWebServices.FileAttachmentType
     ExchangeWebServices.ItemAttachmentType

Example

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.

 [C#]
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);
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003,

Target Platforms

Windows 98, Windows 2000, Windows 2000 Server, Windows CE, Windows Longhorn, Windows 98 Second Edition, Pocket PC, Smart Phone, Windows Server 2003, Windows XP Professional with Service Pack 2 (SP2)