2013-02-01 1 views
4

ItemAttachment을 저장할 수 있습니까? FileAttachment 위해 우리는EWS 관리 API를 사용하여 ItemAttachments를 저장하는 방법

if(attachment is FileAttachment) 
    { 
     FileAttachment fAttachment = new FileAttachment(); 
     fAttachment.Load("D:\\Stream" + fAttachment.Name); 
    } 

무엇 ItemAttachment의 경우에 대해, 저장 API 코드 관리 다음 EWS를 사용하고 계십니까? 어떻게하면 ItemAttachment을 지정한 파일에 저장할 수 있습니까?

+0

어떤 버전 :

당신이 항목에 대한 MimeContent를로드 할 필요 ItemAttachments를 들어

, 당신은 단순히 파일/출력 [ ".eml 인", "로 .msg"]에 기록 할 수 있습니다 .WebServices.dll 당신이 사용합니까? –

답변

6

물론 이것은 여전히 ​​중요한 문제는 아니지만, 내가 한 것처럼 미래를 가로 질러서 넘어지면 누구에게나 나누어 줄 것입니다. Microsoft.Exchange의

if (attachment is FileAttachment) 
{ 
    FileAttachment fileAttachment = attachment as FileAttachment; 

    // Load attachment contents into a file. 
    fileAttachment.Load(<file path>); 
} 
else // Attachment is an ItemAttachment (Email) 
{ 
    ItemAttachment itemAttachment = attachment as ItemAttachment; 

    // Load Item with additionalProperties of MimeContent 
    itemAttachment.Load(EmailMessageSchema.MimeContent); 

    // MimeContent.Content will give you the byte[] for the ItemAttachment 
    // Now all you have to do is write the byte[] to a file 
    File.WriteAllBytes(<file path>, itemAttachment.Item.MimeContent.Content); 
} 
+0

어떤 버전의 Microsoft.Exchange.WebServices.dll을 사용하십니까? –

+0

지연되어 죄송합니다. Microsoft EWS Managed API 2.0을 사용 중입니다. 정보 : 라이브러리에 대한 직접 링크 :

+0

문제 없습니다. 이 itemAttachment.Load (EmailMessageSchema.MimeContent);는 내가 누락 된 부분이었습니다. –