none
Question with Exchange Web Services RRS feed

  • Question

  • I've got one application that works with Exchange Web Services (NOT Managed API), I would like to know how to Exclude all draft items from one folder. I know there's one property: "itemIsDraft", but I don't know how to create the filter. Thanks.
    Wednesday, February 8, 2012 8:37 AM

Answers

  • Try

                ExchangeServiceBinding esb = new ExchangeServiceBinding();
                esb.Credentials = new NetworkCredential("user", "pass");
                esb.Url = @"https://server.outlook.com/ews/exchange.asmx";
    
                DistinguishedFolderIdType diFolder = new DistinguishedFolderIdType();
                BaseFolderIdType[] biArray = new BaseFolderIdType[1];
                diFolder.Id = DistinguishedFolderIdNameType.drafts;
                biArray[0] = diFolder;
    
                FindItemType fiFindItemRequest = new FindItemType();
                ItemResponseShapeType ipItemProperties = new ItemResponseShapeType();
                fiFindItemRequest.Traversal = ItemQueryTraversalType.Shallow;
                ipItemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
    
                PathToExtendedFieldType PR_MESSAGE_FLAGS = new PathToExtendedFieldType();
                PR_MESSAGE_FLAGS.PropertyTag = "0x0E07";
                PR_MESSAGE_FLAGS.PropertyType = MapiPropertyTypeType.Integer;
    
                fiFindItemRequest.ItemShape = ipItemProperties;
                fiFindItemRequest.ParentFolderIds = biArray;
                //Add Restriction 
                RestrictionType ffRestriction = new RestrictionType();
                ExcludesType exToType = new ExcludesType();
                          
                ExcludesValueType evType = new ExcludesValueType();
                evType.Value = "0x8";
                exToType.Item = PR_MESSAGE_FLAGS;
                exToType.Bitmask = evType;
                ffRestriction.Item = exToType;
                fiFindItemRequest.Restriction = ffRestriction;
                FindItemResponseType frFindItemResponse = esb.FindItem(fiFindItemRequest);
                if (frFindItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
                {
                    foreach (FindItemResponseMessageType firmtMessage in frFindItemResponse.ResponseMessages.Items)
                    {
                        Console.WriteLine("Number of Items Found : " + firmtMessage.RootFolder.TotalItemsInView);
                        if (firmtMessage.RootFolder.TotalItemsInView > 0)
                        {
                            foreach (ItemType miMailboxItem in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)
                            {
                                Console.Write(miMailboxItem.Subject);
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Error Occured");
                    Console.WriteLine(frFindItemResponse.ResponseMessages.Items[0].MessageText.ToString());
                }
    Cheers
    Glen
    • Marked as answer by Luis.Atempo Monday, February 13, 2012 3:05 PM
    Friday, February 10, 2012 4:28 AM

All replies

  • You will need to use a Restriction see http://msdn.microsoft.com/en-us/library/cc795474%28v=EXCHG.80%29.aspx for a sample. The property you want to create the restriction on would be PR_MSG_Status http://msdn.microsoft.com/en-us/library/cc839915.aspx . You should be able to use a ExcludesType Restriction with that prop

    Cheers
    Glen

    Thursday, February 9, 2012 7:03 AM
  • Can you provide me one example?.
    Thursday, February 9, 2012 7:57 AM
  • Try

                ExchangeServiceBinding esb = new ExchangeServiceBinding();
                esb.Credentials = new NetworkCredential("user", "pass");
                esb.Url = @"https://server.outlook.com/ews/exchange.asmx";
    
                DistinguishedFolderIdType diFolder = new DistinguishedFolderIdType();
                BaseFolderIdType[] biArray = new BaseFolderIdType[1];
                diFolder.Id = DistinguishedFolderIdNameType.drafts;
                biArray[0] = diFolder;
    
                FindItemType fiFindItemRequest = new FindItemType();
                ItemResponseShapeType ipItemProperties = new ItemResponseShapeType();
                fiFindItemRequest.Traversal = ItemQueryTraversalType.Shallow;
                ipItemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
    
                PathToExtendedFieldType PR_MESSAGE_FLAGS = new PathToExtendedFieldType();
                PR_MESSAGE_FLAGS.PropertyTag = "0x0E07";
                PR_MESSAGE_FLAGS.PropertyType = MapiPropertyTypeType.Integer;
    
                fiFindItemRequest.ItemShape = ipItemProperties;
                fiFindItemRequest.ParentFolderIds = biArray;
                //Add Restriction 
                RestrictionType ffRestriction = new RestrictionType();
                ExcludesType exToType = new ExcludesType();
                          
                ExcludesValueType evType = new ExcludesValueType();
                evType.Value = "0x8";
                exToType.Item = PR_MESSAGE_FLAGS;
                exToType.Bitmask = evType;
                ffRestriction.Item = exToType;
                fiFindItemRequest.Restriction = ffRestriction;
                FindItemResponseType frFindItemResponse = esb.FindItem(fiFindItemRequest);
                if (frFindItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
                {
                    foreach (FindItemResponseMessageType firmtMessage in frFindItemResponse.ResponseMessages.Items)
                    {
                        Console.WriteLine("Number of Items Found : " + firmtMessage.RootFolder.TotalItemsInView);
                        if (firmtMessage.RootFolder.TotalItemsInView > 0)
                        {
                            foreach (ItemType miMailboxItem in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)
                            {
                                Console.Write(miMailboxItem.Subject);
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Error Occured");
                    Console.WriteLine(frFindItemResponse.ResponseMessages.Items[0].MessageText.ToString());
                }
    Cheers
    Glen
    • Marked as answer by Luis.Atempo Monday, February 13, 2012 3:05 PM
    Friday, February 10, 2012 4:28 AM