2013-02-26 62 views
5

我試圖使用EWS約會的擴展屬性,但我似乎無法再次找到約會。集合屬性部分等於在這個問題上所示:Exchange Webservice託管API - 通過擴展屬性查找項目

How to Update an Appointment from Exchange Web Service Managed API 2.0 in ASP.NET

當我嘗試檢索約會,我都遵循這些例子:

http://msdn.microsoft.com/en-us/uc14trainingcourse_5l_topic3#_Toc254008129 http://msdn.microsoft.com/en-us/library/exchange/dd633697(v=exchg.80).aspx

但我在查找時從未得到任何返回的約會。

下面是查找代碼:

 ItemView view = new ItemView(10); 

     // Get the GUID for the property set. 
     Guid MyPropertySetId = new Guid("{" + cGuid + "}"); 

     // Create a definition for the extended property. 
     ExtendedPropertyDefinition extendedPropertyDefinition = 
      new ExtendedPropertyDefinition(MyPropertySetId, "AppointmentID", MapiPropertyType.String); 

     view.PropertySet = 
     new PropertySet(
       BasePropertySet.IdOnly, 
       ItemSchema.Subject, 
       AppointmentSchema.Start, 
       AppointmentSchema.End, extendedPropertyDefinition); 

     SearchFilter filter = new SearchFilter.Exists(extendedPropertyDefinition); 

     FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, filter, 
      view); 

任何幫助是極大的讚賞。

編輯: 當我試圖創建屬性,如文檔顯示:

http://msdn.microsoft.com/en-us/library/exchange/dd633654(v=exchg.80).aspx

它,因爲它的一個GUID IM作爲增加屬性值失敗。 : -/

再次編輯: 只是試圖讓今天所有的約會,並從我剛剛創建的任命獲得的財產,和它說的一樣,我存儲,而不{},所以它必須是與過濾器的東西。

編輯再次* 它具有財產以後做

ExtendedPropertyDefinition extendedProperty = new ExtendedPropertyDefinition(

如果我使用:

new ExtendedPropertyDefinition(
       DefaultExtendedPropertySet.Appointment, 
       "AppointmentID", 
       MapiPropertyType.String); 

它發現所有性質的約會,但如果我搜索一個特定一個:

Guid MyPropertySetId = new Guid("{" + cGuid + "}"); 

ExtendedPropertyDefinition extendedProperty = 
      new ExtendedPropertyDefinition(
       MyPropertySetId, 
       "AppointmentID", 
       MapiPropertyType.String); 

然後沒有發現。

回答

20

這裏有一個samplecode如何創建具有的自訂預約,並在保存後發現:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); 
     service.AutodiscoverUrl("[email protected]"); 

     ExtendedPropertyDefinition def = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "AppointmenId", MapiPropertyType.String); 

     Guid testid = Guid.NewGuid(); 

     Appointment appointment = new Appointment(service); 
     appointment.Subject = "Test"; 
     appointment.Start = DateTime.Now.AddHours(1); 
     appointment.End = DateTime.Now.AddHours(2); 
     appointment.SetExtendedProperty(def, testid.ToString()); 
     appointment.Save(WellKnownFolderName.Calendar); 

     SearchFilter filter = new SearchFilter.IsEqualTo(def, testid.ToString()); 

     FindItemsResults<Item> fir = service.FindItems(WellKnownFolderName.Calendar, filter, new ItemView(10)); 

希望這可以幫助你......

+0

謝謝,生病了試試看。 – Jacob 2013-02-28 13:13:42

+0

適合我的作品!非常感謝! – Jacob 2013-02-28 14:05:12

+0

你的歡迎...也許下一次你可以幫我;) 你可以請設置「是有益的」;) – 2013-02-28 15:35:56

0

您在收件箱中搜索約會。在那裏你永遠不會找到他們。嘗試在日曆中進行搜索。

+0

是的,我在錯誤的文件夾中搜索,但它仍然沒有發現: -/ – Jacob 2013-02-27 11:54:24

+0

嗯...也許這是因爲你如何創建你的propertydefinition。 試試這段代碼: ExtendedPropertyDefinition propdef = new ExtendedPropertyDefinition(Microsoft.Exchange.WebServices.Data。DefaultExtendedPropertySet.PublicStrings,name,MapiPropertyType.String); 用於添加和搜索。我也有使用Guid-way的問題。這一個更容易,並在我的代碼中工作。 – 2013-02-27 13:39:50

0

下面是將guid作爲擴展屬性並根據guid獲取約會的示例。

private static readonly PropertyDefinitionBase AppointementIdPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "AppointmentID", MapiPropertyType.String); 
public static PropertySet PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, AppointementIdPropertyDefinition); 


//Setting the property for the appointment 
public static void SetGuidForAppointement(Appointment appointment) 
{ 
    try 
    { 
     appointment.SetExtendedProperty((ExtendedPropertyDefinition)AppointementIdPropertyDefinition, Guid.NewGuid().ToString()); 
     appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone); 
    } 
    catch (Exception ex) 
    { 
     // logging the exception 
    } 
} 

//Getting the property for the appointment 
public static string GetGuidForAppointement(Appointment appointment) 
{ 
    var result = ""; 
    try 
    { 
     appointment.Load(PropertySet); 
     foreach (var extendedProperty in appointment.ExtendedProperties) 
     { 
      if (extendedProperty.PropertyDefinition.Name == "AppointmentID") 
      { 
       result = extendedProperty.Value.ToString(); 
      } 
     } 
    } 
    catch (Exception ex) 
    { 
    // logging the exception 
    } 
    return result; 
} 
+0

這是我用來設置Guid的代碼。第二部分從約會中檢索guid。我的問題是我需要找到具體的約會時,只有Guid。 – Jacob 2013-02-27 18:07:01

+0

好吧,當你找到約會從某些日期到其他人,那麼你使用你提取的Guid(如果它匹配或不匹配)應用一個if case搜索。 – BraveHeart 2013-02-28 12:00:15

相關問題