如何从 Outlook 加载项中接受的 ICS 文件中检索 UID?
How do I retrieve a UID from a ICS file being accepted in an Outlook add in?
感谢观看。
我正在开发 Outlook Add-in 并且需要在用户接受时访问嵌入在 .ics 文件中的 UID 值:
如果我查看 .ICS 文件中的原始数据,我可以看到 UID 在那里:
我想知道当用户接受会议时会触发什么事件(我可以附加到该事件),一旦我有了被接受的 outlook object,我如何从中检索 UID是吗?
更新:
感谢 Dmitry Streblechenko 的帮助,我现在了解到全局约会 ID 只是 UID 的编码版本。他的工具 OutlookSpy 在看到这一点时非常有用。也就是说,我仍然停留在最后一部分,即在 C# 中将全局约会 ID 转换为 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("[=11=]", string.Empty);
//Here is the result
var uid = test;
}else{
// Bad format!!!
}
}
您可以从 AppointmentItem.GlobalAppointmentID 属性 中提取它。其格式记录在 https://msdn.microsoft.com/en-us/library/ee157690(v=exchg.80).aspx。如果数据部分以 "vCal-Uid" 开头,则 UID 紧随其后。
感谢观看。
我正在开发 Outlook Add-in 并且需要在用户接受时访问嵌入在 .ics 文件中的 UID 值:
如果我查看 .ICS 文件中的原始数据,我可以看到 UID 在那里:
我想知道当用户接受会议时会触发什么事件(我可以附加到该事件),一旦我有了被接受的 outlook object,我如何从中检索 UID是吗?
更新:
感谢 Dmitry Streblechenko 的帮助,我现在了解到全局约会 ID 只是 UID 的编码版本。他的工具 OutlookSpy 在看到这一点时非常有用。也就是说,我仍然停留在最后一部分,即在 C# 中将全局约会 ID 转换为 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("[=11=]", string.Empty);
//Here is the result
var uid = test;
}else{
// Bad format!!!
}
}
您可以从 AppointmentItem.GlobalAppointmentID 属性 中提取它。其格式记录在 https://msdn.microsoft.com/en-us/library/ee157690(v=exchg.80).aspx。如果数据部分以 "vCal-Uid" 开头,则 UID 紧随其后。