Pergunta

In EWS Managed API you can do:

Folder inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
inbox.FindItems(...)

or you could do:

service.FindItems(WellKnownFolderName.Inbox, filter, view);

as described here: http://msdn.microsoft.com/en-us/library/exchange/dd633693(v=exchg.80).aspx

What is the difference between both methods? Which one is preferred? (I don't think you really need to bind to a folder?)

Foi útil?

Solução

Folder.Bind Allow you to bind the folder that you want. You can even bind to the folder of other user if you have permission. Or whatever folder once you recover the FolderID (you can use it as a parameter)

For example, If I am an exchange administrator and I would like to get the Root Folder of a user who has the smtp address "john.snow@mail.com", I would bind to the folder this way:

Folder FolderBind =
                   Folder.Bind(service, new FolderId
                       (WellKnownFolderName.MsgFolderRoot, "john.snow@mail.com));

Once you have the FolderBind loaded with whatever folder you want, you can use the other method, because it receives the Folder.ID parameter that you may not know. But know thanks to Folder.Bind, you have the FolderID of the MsgFolderRoot of "john.snow@mail.com", so you can perform a search inside his items with:

FindItemsResults<Item> findResults = service.FindItems(FolderBind.Id, searchFilter, view);

I don't know If I made myself clear. I you have more doubts just ask.

EDIT:

You can give to the FindItems a refinated searchFilter that will allow you to get items attending to some requirements. Like searching emails with attachment. Searching emails older than some date. ett.

Here an example:

List<SearchFilter> searchORFilterCollection = new List<SearchFilter>();
            searchORFilterCollection.Add( new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments, true));
            searchORFilterCollection.Add(new SearchFilter.IsLessThan(EmailMessageSchema.DateTimeReceived,DateTime.Now.AddMonths(-3)));


SearchFilter searchFilter= new SearchFilter.SearchFilterCollection(LogicalOperator.And,searchORFilterCollection.ToArray());
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top