2013-08-23 36 views
3

我需要在用戶的日曆約會中搜索子字符串。我沒有關於約會的其他信息(GUID,開始日期等)。我只知道一個特定的子字符串在主體中。EWS搜索子任務的約會正文

我已經閱讀了一些關於如何獲得約會正文的文章,但他們通過GUID或主題進行搜索。我試圖使用下面的代碼來搜索正文中的子字符串,但是我得到一個錯誤,我無法在FindItems中使用正文。

有沒有辦法做到這一點?假設我無法從約會中獲得任何其他信息,是否還有其他方法可以採用?

 //Variables 
     ItemView view = new ItemView(10); 
     view.PropertySet = new PropertySet(EmailMessageSchema.Body); 

     SearchFilter sfSearchFilter; 
     FindItemsResults<Item> findResults; 

     foreach (string s in substrings) 
     { 
      //Search for messages with body containing our permURL 
      sfSearchFilter = new SearchFilter.ContainsSubstring(EmailMessageSchema.Body, s); 
      findResults = service.FindItems(WellKnownFolderName.Calendar, sfSearchFilter, view); 

      if (findResults.TotalCount != 0) 
      { 
       Item appointment = findResults.FirstOrDefault(); 
       appointment.SetExtendedProperty(extendedPropertyDefinition, s); 
      } 

回答

3

所以事實證明,你可以搜索身體,但你不能返回身體FindItems。如果你想使用它,你必須稍後加載它。因此,不是將我的屬性設置爲body,而是將其設置爲IdOnly,然後將SearchFilter設置爲遍歷ItemSchema的主體。

 //Return one result--there should only be one in this case 
     ItemView view = new ItemView(1); 
     view.PropertySet = new PropertySet(BasePropertySet.IdOnly); 

     //variables 
     SearchFilter sfSearchFilter; 
     FindItemsResults<Item> findResults; 

     //for each string in list 
     foreach (string s in permURLs) 
     { 
      //Search ItemSchema.Body for the string 
      sfSearchFilter = new SearchFilter.ContainsSubstring(ItemSchema.Body, s); 
      findResults = service.FindItems(WellKnownFolderName.Calendar, sfSearchFilter, view); 

      if (findResults.TotalCount != 0) 
      { 
       Item appointment = findResults.FirstOrDefault(); 
       appointment.SetExtendedProperty(extendedPropertyDefinition, s); 
       ... 
       appointment.Load(new PropertySet(ItemSchema.Body)); 
       string strBody = appointment.Body.Text; 
      } 
     }