2012-08-06 15 views
8

come alcuni altri hanno già discusso di questo problema (ad esempio, Exchange web services: why is ItemId not constant?), voglio parlare della soluzione, ho fatto ciò che le persone hanno suggerito timbrando il Guid come una proprietà estesa, Per me questa soluzione è una specie di bello (anche se non so come farlo funzionare con le occorrenze) ma solo fino a quando l'applicazione funziona, una volta che l'applicazione riavvia le proprietà estese degli elementi scompaiono, quindi il mio problema ora è "Come stampare il proprietà estesa sull'elemento EWS e renderlo costantemente lì?” Questo è il codice di aggiornare gli elementi di calendario (appuntamenti)Servizi Web di Exchange: perché ItemId non è costante? [continua]

public void SetGuidForAppointement(Appointment appointment) 
{   
appointment.SetExtendedProperty((ExtendedPropertyDefinition)_appointementIdPropertyDefinition, Guid.NewGuid().ToString()); 
appointment.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone); 
} 

e questi sono la definizione proprietà necessaria sopra.

_appointementIdPropertyDefinition = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, "AppointmentID", MapiPropertyType.String); 
      _propertyDefinitionBases = new PropertyDefinitionBase[] { _appointementIdPropertyDefinition, ItemSchema.ParentFolderId, AppointmentSchema.Start, AppointmentSchema.End, 
AppointmentSchema.LegacyFreeBusyStatus, AppointmentSchema.Organizer }; 
      PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, _propertyDefinitionBases); 

Quindi, se qualcuno ha fatto questo prima potesse lui/lei mi fornirà un esempio che mantiene la proprietà estesa impresso sulla voce, anche se l'applicazione è uscito. Grazie

+0

Ciao, cosa intendi esattamente con "una volta che l'applicazione riavvia le proprietà estese degli elementi scompaiono"? –

+0

Ho risposto alla mia domanda nella risposta qui sotto :) – BraveHeart

+1

Lo so. :) Ma uso anche proprietà estese, e sono curioso di sapere se è possibile che il valore che immagazzino in esso venga perso ad un certo punto? –

risposta

9

Ho trovato la soluzione al mio problema dopo un po 'di tentativi e ricerche.

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

Ehi! questo ha funzionato anche per me. Grazie ! –

+0

Portato questo a VB da usare lì. Usato come: Dim guid come stringa = GetGuidForAppointment (appuntamento) Se String.IsNullOrEmpty (GUID) Poi SetGuidForAppointment (appuntamento) guid = GetGuidForAppointment (appuntamento) End If – Brent

Problemi correlati