【发布时间】:2017-07-04 16:32:10
【问题描述】:
感谢收看。
我正在开发一个 Outlook 插件,并且需要在用户接受时访问嵌入在 .ics 文件中的 UID 值:
如果我查看 .ICS 文件中的原始数据,我可以看到 UID 在那里:
我想知道当用户接受会议时会触发什么事件(我可以附加到该事件),一旦我获得了被接受的 Outlook 对象,我如何从中检索 UID?
更新:
感谢 Dmitry Streblechenko 的帮助,我现在了解到全局约会 ID 只是 UID 的编码版本。他的工具OutlookSpy在看到这一点时非常有用。也就是说,我仍然停留在最后一部分,即将全局约会 ID 转换为 C# 中的 UID。 Google 将我带到此示例以转换 EntryId 属性,但我找不到正确的架构或十六进制代码来获取全局约会 ID 属性和解码值。如有任何关于如何修改以下全局预约 ID 代码的建议,我们将不胜感激:
var oPA = appt.PropertyAccessor;
//Get EntryId Value
var entryIDProperty = "http://schemas.microsoft.com/mapi/proptag/0x0FFF0102";
var entryId= oPA.BinaryToString(oPA.GetProperty(entryIDProperty));
//Now how to get the Global Appointment ID??
var globalApptProperty = http://schemas.microsoft.com/mapi/proptag/0x????????";
var globalId= oPA.BinaryToString(oPA.GetProperty(globalApptProperty ));
提前致谢。
解决方案
我意识到这可能不是实现目标的最佳方式,但它确实有效,所以我发帖以防它帮助其他人:
var item = Item as Outlook.MeetingItem;
var appt = item.GetAssociatedAppointment(false);
var oPA = appt.PropertyAccessor;
//This parses the Global Appointment ID to a byte array. We need to retrieve the "UID" from it (if available).
byte[] bytes = (byte[]) oPA.StringToBinary(appt.GlobalAppointmentID);
//According to https://msdn.microsoft.com/en-us/library/ee157690(v=exchg.80).aspx we don't need first 40 bytes
if (bytes.Length>=40)
{
byte[] bytesThatContainData = new byte[bytes.Length - 40];
Array.Copy(bytes, 40, bytesThatContainData, 0, bytesThatContainData.Length);
//In some cases, there won't be a UID.
var test = Encoding.UTF8.GetString(bytesThatContainData, 0, bytesThatContainData.Length);
if (test.StartsWith("vCal-Uid"))
{
//remove vCal-Uid from start string and special symbols
test = test.Replace("vCal-Uid", string.Empty);
test = test.Replace("\u0001", string.Empty);
test = test.Replace("\0", string.Empty);
//Here is the result
var uid = test;
}else{
// Bad format!!!
}
}
【问题讨论】:
标签: c# vsto outlook-addin mapi