How to use MessageQuery to fetch from Inbox

Vote:
 

I'm struggling to write a Query to fetch DirectMessages from a users inbox but I can't get it to work. 

I get all kinds of strange errors when fiddleing around. Ideas and input is much appreciated. 

 

This is what I currently have: 

 

            var mq = new MessageQuery(); 

            var r = newMessageRecipientCollectionCriterion();

            r.Containing = new MessageRecipientCriterion();  

            r.Containing.Recipient = new UserCriterion();

            r.Containing.Recipient.ID = new IntegerCriterion();

            r.Containing.Recipient.ID.Includes = new IntegerInCriterion();

            r.Containing.Recipient.ID.Includes.Values.Add(_user.ID);

            var f = new FolderCriterion();

            f.Container = newDirectMessageContainerCriterion();

            f.Container.User = new UserCriterion();

            f.Container.User.ID = new IntegerCriterion {Value = _user.ID};

            f.Container.Folders = new FolderBaseCollectionCriterion();

            f.Container.Folders.Containing = new SystemFolderCriterion { FolderType = new SystemCriterion {Value = SystemFolderType.Inbox} };

            f.Container.Folders.Containing.ID = new IntegerCriterion {Value = GetInbox().ID};

            r.Containing.Folder = f;

 

            mq.Recipients = r;

 

            mq.SendDate = new DateTimeCriterion();

            mq.OrderBy.Add(new CriterionSortOrder(mq.SendDate, SortingDirection.Descending));

               

           QueryHandler.Instance.RemoveQueryResultCache(mq);

           var messages = DirectMessageHandler.Instance.GetQueryResult(mq);

 

 

 

 

#65965
Feb 15, 2013 21:43
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.