C# 如何使用EWS管理的API通过id获取附件?
是否可以使用EWS管理的API直接获取附件,而不首先获取其包含的电子邮件 比如:C# 如何使用EWS管理的API通过id获取附件?,c#,exchange-server,exchangewebservices,C#,Exchange Server,Exchangewebservices,是否可以使用EWS管理的API直接获取附件,而不首先获取其包含的电子邮件 比如: FileAttachment attach = FileAttachment.Bind(ewsService, attachId); 我找不到用于此的任何方法。您可以使用ExchangeService类的GetAttachments方法,这允许您同时批处理一个或多个GetAttachment请求,例如: FindItemsResults<Item> fItems = service.Find
FileAttachment attach = FileAttachment.Bind(ewsService, attachId);
我找不到用于此的任何方法。您可以使用ExchangeService类的GetAttachments方法,这允许您同时批处理一个或多个GetAttachment请求,例如:
FindItemsResults<Item> fItems = service.FindItems(WellKnownFolderName.Inbox,new ItemView(10));
PropertySet psSet = new PropertySet(BasePropertySet.FirstClassProperties);
service.LoadPropertiesForItems(fItems.Items, psSet);
List<Attachment> atAttachmentsList = new List<Attachment>();
foreach(Item ibItem in fItems.Items){
foreach(Attachment at in ibItem.Attachments){
atAttachmentsList.Add(at);
}
}
ServiceResponseCollection<GetAttachmentResponse> gaResponses = service.GetAttachments(atAttachmentsList.ToArray(), BodyType.HTML, null);
foreach (GetAttachmentResponse gaResp in gaResponses)
{
if (gaResp.Result == ServiceResult.Success)
{
if (gaResp.Attachment is FileAttachment)
{
Console.WriteLine("File Attachment");
}
if (gaResp.Attachment is ItemAttachment)
{
Console.WriteLine("Item Attachment");
}
}
}
FindItemsResults-fItems=service.FindItems(WellKnownFolderName.Inbox,新项目视图(10));
PropertySet psSet=新的PropertySet(BasePropertySet.FirstClassProperties);
项目(fItems.Items,psSet)的服务负荷属性;
List atAttachmentsList=新列表();
foreach(fItems.Items中的项目ibItem){
foreach(附件在ibItem.附件中){
atAttachmentsList.Add(在);
}
}
ServiceResponseCollection GarResponses=service.GetAttachments(ataAttachmentsList.ToArray(),BodyType.HTML,null);
foreach(GetAttachmentResponse gaResp中的gaResp)
{
if(gaResp.Result==servicesult.Success)
{
如果(gaResp.Attachment是FileAttachment)
{
Console.WriteLine(“文件附件”);
}
如果(附件是项目附件)
{
控制台写入线(“项目附件”);
}
}
}