get calendar by uid (c#)
static void Main(string[] args)
{
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
const string id = "040000008200E00074C5B7101A82E008000000007069352667BBC9010000000000000000100000000C74ABD802575A41BC09B0E12352657B";
string bufferString = GetObjectIdStringFromUid(id);
var service = new ExchangeServiceBinding
{
Url = "https //w2k3x64/ews/exchange.asmx",
Credentials = new NetworkCredential("bob", "Password!", "contoso"),
RequestServerVersionValue = new RequestServerVersion { Version = ExchangeVersionType.Exchange2007_SP1}
};
var response = service.FindItem(new FindItemType
{
ParentFolderIds = new[] { new DistinguishedFolderIdType { Id = DistinguishedFolderIdNameType.calendar } },
ItemShape = new ItemResponseShapeType
{
BaseShape = DefaultShapeNamesType.AllProperties,
},
Restriction = new RestrictionType {
Item = new IsEqualToType
{
Item = new PathToExtendedFieldType
{
DistinguishedPropertySetId = DistinguishedPropertySetType.Meeting,
DistinguishedPropertySetIdSpecified = true,
PropertyId = 0x03,
PropertyIdSpecified = true,
PropertyType = MapiPropertyTypeType.Binary
},
FieldURIOrConstant = new FieldURIOrConstantType
{
Item = new ConstantValueType
{
Value = bufferString
}
}
}
}
});
var messageType = ((FindItemResponseMessageType) response.ResponseMessages.Items[0]);
Console.Out.WriteLine("messageType.ResponseClass = {0}", messageType.ResponseClass);
if (messageType.ResponseClass != ResponseClassType.Success)
{
Console.Out.WriteLine(messageType.MessageText);
return;
}
var returnedItems = messageType.RootFolder.Item as ArrayOfRealItemsType;
if (returnedItems == null || returnedItems.Items == null)
{
Console.Out.WriteLine("Nothing found.");
return;
}
foreach (CalendarItemType item in returnedItems.Items)
{
Console.Out.WriteLine("item.Subject = {0}", item.Subject);
Console.Out.WriteLine("item.UID = {0}", item.UID);
}
Console.ReadLine();
}
private static string GetObjectIdStringFromUid(string id)
{
var buffer = new byte[id.Length/2];
for (int i = 0; i < id.Length/2; i++)
{
var hexValue = byte.Parse(id.Substring(i*2, 2), NumberStyles.AllowHexSpecifier);
buffer[i] = hexValue;
}
return Convert.ToBase64String(buffer);
}