CreateAttachmentType 类

定义

CreateAttachmentType 表示将项目或文件附加到 Exchange 数据库中的指定项的请求。

public ref class CreateAttachmentType : ExchangeWebServices::BaseRequestType
public class CreateAttachmentType : ExchangeWebServices.BaseRequestType
Public Class CreateAttachmentType
Inherits BaseRequestType
继承
CreateAttachmentType

示例

下面的代码示例演示了一个创建附件请求,该请求在 Exchange 数据库中的现有项上创建文件和项目附件。

static void CreateAttachment(ExchangeServiceBinding esb)
{
    // Create the 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 the 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.
    CreateAttachmentType <span class="label">reqCreateAttach</span>= 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.
<span class="label">reqCreateAttach</span>.ParentItemId = item;

    // Add attachments to the request.
<span class="label">reqCreateAttach</span>.Attachments = new AttachmentType[2];
<span class="label">reqCreateAttach</span>.Attachments[0] = itemAttach;
<span class="label">reqCreateAttach</span>.Attachments[1] = fileAttach;

    try
    {
        CreateAttachmentResponseType resp = esb.CreateAttachment(<span class="label">reqCreateAttach</span>);
        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);
    }
}

注解

不能将现有项附加到另一项。 若要附加现有项的内容,请将现有项的 传递给 MimeContent 要创建的附件。 确保为现有项返回的所有属性为 null。 附件中仅应使用多用途 Internet 邮件扩展 (MIME) 内容。 如果尝试将现有项附加到另一项,响应将包含错误,因为 Exchange 数据库不能包含重复的项目标识符。

构造函数

CreateAttachmentType()

构造 CreateAttachmentType 函数初始化 类的新实例 CreateAttachmentType

属性

Attachments

属性 Attachments 获取或设置要为 CreateAttachment作创建的附件。

ParentItemId

属性 ParentItemId 获取或设置 Exchange 数据库中接收附件的父项。

适用于