Compartir a través de


GetAttachmentType Class

The GetAttachmentType class represents a request to get attached items and files on an item in an Exchange database.

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

Syntax

'Declaration
<SerializableAttribute> _
<XmlTypeAttribute(Namespace:="https://schemas.microsoft.com/exchange/services/2006/messages")> _
<GeneratedCodeAttribute("wsdl", "2.0.50727.42")> _
<DebuggerStepThroughAttribute> _
<DesignerCategoryAttribute("code")> _
Public Class GetAttachmentType
    Inherits BaseRequestType
[SerializableAttribute] 
[XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/messages")] 
[GeneratedCodeAttribute("wsdl", "2.0.50727.42")] 
[DebuggerStepThroughAttribute] 
[DesignerCategoryAttribute("code")] 
public class GetAttachmentType : BaseRequestType
[SerializableAttribute] 
[XmlTypeAttribute(Namespace=L"https://schemas.microsoft.com/exchange/services/2006/messages")] 
[GeneratedCodeAttribute(L"wsdl", L"2.0.50727.42")] 
[DebuggerStepThroughAttribute] 
[DesignerCategoryAttribute(L"code")] 
public ref class GetAttachmentType : public BaseRequestType
/** @attribute SerializableAttribute() */ 
/** @attribute XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/messages") */ 
/** @attribute GeneratedCodeAttribute("wsdl", "2.0.50727.42") */ 
/** @attribute DebuggerStepThroughAttribute() */ 
/** @attribute DesignerCategoryAttribute("code") */ 
public class GetAttachmentType extends BaseRequestType
SerializableAttribute 
XmlTypeAttribute(Namespace="https://schemas.microsoft.com/exchange/services/2006/messages") 
GeneratedCodeAttribute("wsdl", "2.0.50727.42") 
DebuggerStepThroughAttribute 
DesignerCategoryAttribute("code") 
public class GetAttachmentType extends BaseRequestType

Remarks

Use the GetItem call to get the attachment identifiers to use in the GetAttachment operation.

Inheritance Hierarchy

System.Object
   ExchangeWebServices.BaseRequestType
    ExchangeWebServices.GetAttachmentType

Example

The following code example shows a get attachment request for two attachments.

static void GetAttachment(ExchangeServiceBinding esb)
{
    // Create the request.
    GetAttachmentTyperequest = new GetAttachmentType();

    // Create the response shape.
    AttachmentResponseShapeType responseShape = new AttachmentResponseShapeType();
    responseShape.BodyType = BodyTypeResponseType.Text;
    responseShape.BodyTypeSpecified = true;

    // Add the response shape to the request.
    request.AttachmentShape = responseShape;

    // Identify the attachment IDs to get.
    RequestAttachmentIdType[] ids = new RequestAttachmentIdType[2];
    ids[0] = new RequestAttachmentIdType();
    ids[1] = new RequestAttachmentIdType();
    ids[0].Id = "AAAlAE1BQG1";
    ids[1].Id = "AAAlAE1Bas";

    // Add the attachment IDs to the request.
    request.AttachmentIds = ids;

    try
    {
        GetAttachmentResponseType response = esb.GetAttachment(request);
        ResponseMessageType[] rmta = response.ResponseMessages.Items;

        foreach (ResponseMessageType responseMessage in rmta)
        { 
            AttachmentInfoResponseMessageType airmt = (responseMessage as AttachmentInfoResponseMessageType);
            AttachmentType[] attachments = airmt.Attachments;
            
            // Type check for item or file attachment.
            foreach (AttachmentType attachment in attachments)
            {
                if (attachment is FileAttachmentType)
                {
                    FileAttachmentType fat = (attachment as FileAttachmentType);

                    // Assumes ASCII encoding.
                    string myContent = ASCIIEncoding.ASCII.GetString(fat.Content);
                }

                // Attachment is item attachment.
                else
                {
                    ItemAttachmentType iat = (attachment as ItemAttachmentType);
                    // TODO: Handle the item attachment.
                }
            }
        }
    }
    catch (Exception x)
    {
        Console.WriteLine(x.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)