CreateAttachmentType Classe
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
A CreateAttachmentType classe representa uma solicitação para anexar um item ou arquivo a um item especificado no banco de dados do Exchange.
public ref class CreateAttachmentType : ExchangeWebServices::BaseRequestType
public class CreateAttachmentType : ExchangeWebServices.BaseRequestType
Public Class CreateAttachmentType
Inherits BaseRequestType
- Herança
Exemplos
O exemplo de código a seguir mostra uma solicitação de criação de anexo que cria um anexo de arquivo e item em um item existente no banco de dados do 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);
}
}
Comentários
Você não pode anexar um item existente a outro item. Para anexar o conteúdo de um item existente, passe o MimeContent do item existente para o anexo que você deseja criar. Certifique-se de anular todas as propriedades retornadas para um item existente. Somente o conteúdo MIME (Extensão do Internet Mail) multiuso deve ser usado no anexo. Se você tentar anexar um item existente a outro item, a resposta conterá um erro porque o banco de dados do Exchange não pode incluir identificadores de item duplicados.
Construtores
CreateAttachmentType() |
O CreateAttachmentType construtor inicializa uma nova instância da CreateAttachmentType classe. |
Propriedades
Attachments |
A Attachments propriedade obtém ou define os anexos a serem criados para a operação CreateAttachment. |
ParentItemId |
A ParentItemId propriedade obtém ou define o item pai no banco de dados do Exchange que recebe os anexos. |