Im ersten Teil wird das ExtendedProperty gesetzt und im zweiten Teil wird es ausgelesen.
String password = "***";
String username = "***";
String domain = "***";
String exUri = "https://domain/EWS/Exchange.asmx";
String SMTPAdresse = "***@***.de";
String ContactFolderName = "KontakteIntern";
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Credentials = new WebCredentials(username, password, domain);
service.Url = new Uri(exUri);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, SMTPAdresse);
var PublicRoot = Folder.Bind(service, WellKnownFolderName.Contacts);
SearchFilter.IsEqualTo filter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, ContactFolderName);
FindFoldersResults FindPublicContactFolder = service.FindFolders(PublicRoot.Id, filter, new FolderView(1));
var ContactFolder = FindPublicContactFolder.Folders[0];
Guid MyPropertySetId = new Guid("{57616c7a-656e-6261-6368-536173636861}");
ExtendedPropertyDefinition extendedPropertyDefinition = new ExtendedPropertyDefinition(MyPropertySetId, "PublicID", MapiPropertyType.String);
// EXTENDED PROP WRITE
FindItemsResults<Item> findResults = service.FindItems(ContactFolder.Id, new ItemView(int.MaxValue));
foreach (Contact item in findResults.Items)
{
Console.WriteLine(item.Subject);
Contact contact = Contact.Bind(service, item.Id);
contact.SetExtendedProperty(extendedPropertyDefinition, item.Id.UniqueId);
contact.Update(ConflictResolutionMode.AlwaysOverwrite);
}
// EXTENDED PROP READ
ItemView view = new ItemView(int.MaxValue);
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, extendedPropertyDefinition);
FindItemsResults<Item> findResults2 = service.FindItems(ContactFolder.Id, view);
foreach (Item item in findResults2.Items)
{
Console.WriteLine(item.Subject);
string PublicID;
if (item.ExtendedProperties.Count > 0)
{
item.TryGetProperty(extendedPropertyDefinition, out PublicID);
Console.WriteLine(PublicID);
}
}
Console.ReadKey();
Kommentare zum Snippet