1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| ExchangeServiceBinding esb = new ExchangeServiceBinding();
esb.Credentials = new NetworkCredential("user", "password", "DOMAIN");
esb.RequestServerVersionValue = new RequestServerVersion();
esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010_SP2;
esb.Url = @"https://mail.domain.com/EWS/Exchange.asmx";
//Je récupère l'id qui est au format Legacy
ItemId itemId = textBoxId.Text;
// Create a request to convert identifiers.
ConvertIdType request = new ConvertIdType();
request.SourceIds = new AlternateIdType[1];
request.SourceIds[0] = new AlternateIdType();
// Convert EwsLegacyId to EwsId.
request.SourceIds[0].Format = IdFormatType.EwsLegacyId;
(request.SourceIds[0] as AlternateIdType).Id = itemId.ToString();
(request.SourceIds[0] as AlternateIdType).Mailbox = "mail@domain.com";
request.DestinationFormat = IdFormatType.EwsId;
// Send the request and get the response.
ConvertIdResponseType response = esb.ConvertId(request);
ResponseMessageType[] rmta = response.ResponseMessages.Items;
foreach (ResponseMessageType rmt in rmta)
{
ConvertIdResponseMessageType cirmt = (rmt as ConvertIdResponseMessageType);
AlternateIdType myId = (cirmt.AlternateId as AlternateIdType);
if (myId != null)
{
string format = myId.Format.ToString();
string identifier = myId.Id;
textBoxId.Text = identifier;
string mailbox = myId.Mailbox;
}
}
string id = textBoxId.Text;
Contact contact = Contact.Bind(_service, id);
// Update the contact's surname and company name.
contact.Surname = textBoxNom.Text;
contact.GivenName = textBoxPrenom.Text;
// Update the contact's business phone number.
contact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = textBoxNumTelEntreprise.Text;
contact.PhoneNumbers[PhoneNumberKey.HomePhone] = textBoxNumTelPrive.Text;
contact.PhoneNumbers[PhoneNumberKey.MobilePhone] = textBoxNumTelMobile.Text;
contact.PhoneNumbers[PhoneNumberKey.BusinessPhone2] = textBoxNumTelEntrepriseMobile.Text;
// Update the contact's second email address.
contact.EmailAddresses[EmailAddressKey.EmailAddress1] = new Microsoft.Exchange.WebServices.Data.EmailAddress(textBoxMailFirst.Text);
contact.EmailAddresses[EmailAddressKey.EmailAddress2] = new Microsoft.Exchange.WebServices.Data.EmailAddress(textBoxMailSec.Text);
PhysicalAddressEntry paEntryHome = null;
PhysicalAddressEntry paEntryBusiness = null;
paEntryHome = contact.PhysicalAddresses[PhysicalAddressKey.Home];
paEntryBusiness = contact.PhysicalAddresses[PhysicalAddressKey.Business];
//Specifi the home address
paEntryHome.Street = textBoxRuePerso.Text;
paEntryHome.City = textBoxVillePerso.Text;
paEntryHome.State = "";
paEntryHome.PostalCode = textBoxCpPerso.Text;
paEntryHome.CountryOrRegion = textBoxPaysPerso.Text;
// Specify the business address.
paEntryBusiness.Street = textBoxRuePro.Text;
paEntryBusiness.City = textBoxVillePro.Text;
paEntryBusiness.State = "";
paEntryBusiness.PostalCode = textBoxCpPro.Text;
paEntryBusiness.CountryOrRegion = textBoxPaysPro.Text;
// Save the contact.
try
{
contact.Update(ConflictResolutionMode.AlwaysOverwrite);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
} |