正在尝试从 Outlook table 收件箱获取 DASL 属性 值
Attempting to get DASL property value from the Outlook table inbox
我正在尝试读取此线程中提到的 DASL 值 PR_LONGTERM_ENTRYID_FROM_TABLE 0x66700102 -
get outlook mailitem for message taken from outlook table
我遇到的问题是下面完整示例中代码中的以下行-
string ltEntryid = (string)nextRow["http://schemas.microsoft.com/mapi/proptag/0x66700102".ToString()];
抛出异常"Cannot convert type 'byte[]' to 'string'"
我可能会以错误的方式解决这个问题,所以我正在寻找一些建议。我可以很好地阅读所有其他表格行(示例 - “EntryID(短期),MessageClass,Unread,SenderEmailType)。
const string unReadfilter = "[UnRead] = true";
Outlook.Table table = folder.GetTable(unReadfilter, Outlook.OlTableContents.olUserItems);
// Remove the default column set.
table.Columns.RemoveAll();
// Add columns to the table
table.Columns.Add("Unread");
table.Columns.Add("EntryID");
table.Columns.Add("MessageClass");
table.Columns.Add("SenderEmailType");
table.Columns.Add("SenderEmailAddress");
// PR_LONGTERM_ENTRYID_FROM_TABLE
table.Columns.Add("http://schemas.microsoft.com/mapi/proptag/0x66700102".ToString());
// sort table
table.Sort("Unread", true);
while (!table.EndOfTable)
{
Outlook.Row nextRow = table.GetNextRow();
bool unRead = (bool)nextRow["Unread"];
Debug.WriteLine(unRead);
string msgClass = (string)nextRow["MessageClass"];
Debug.WriteLine(msgClass);
string eId = (string)nextRow["EntryID"];
Debug.WriteLine(eId);
string sEaddr = (string)nextRow["SenderEmailAddress"];
Debug.WriteLine(sEaddr);
string sEtype = (string)nextRow["SenderEmailType"];
Debug.WriteLine(sEtype);
// PR_LONGTERM_ENTRYID_FROM_TABLE ***Exception with the following line***
string ltEntryid = (string)nextRow["http://schemas.microsoft.com/mapi/proptag/0x66700102".ToString()];
Debug.WriteLine(ltEntryid);
if (msgClass.Equals("IPM.Note"))
{
//write to string list
dailyMiInboxList.Add(unRead.ToString());
dailyMiInboxList.Add(msgClass);
dailyMiInboxList.Add(eId);
dailyMiInboxList.Add(sEaddr);
dailyMiInboxList.Add(sEtype);
dailyMiInboxList.Add(sEaddr);
dailyMiInboxList.Add(ltEntryid);
}
}
PT_BINARY 属性 作为字节数组返回,但您将其转换为字符串。如果要将其转换为十六进制字符串,请使用 MAPIFolder.PropertyAccessor.BinaryToString()
.
好的,我在德米特里的帮助下解决了这个问题。
首先将此 dasl 属性 添加到 table -
// PR_LONGTERM_ENTRYID_FROM_TABLE
table.Columns.Add("http://schemas.microsoft.com/mapi/proptag/0x66700102".ToString());
我不应该包括 tostring 所以它应该写成如下-
table.Columns.Add(@"http://schemas.microsoft.com/mapi/proptag/0x66700102");
接下来在 While 循环中,要从字节数组转换 PT_BINARY 属性 使用它来转换行-
string PR_LONGTERM_ENTRYID_FROM_TABLE = "http://schemas.microsoft.com/mapi/proptag/0x66700102";
string ltEntryId = (string)nextRow.BinaryToString(PR_LONGTERM_ENTRYID_FROM_TABLE);
Debug.Print(ltEntryId);
特别是这些评论-
• 为表示二进制 (PT_BINARY) 值的给定列返回的值取决于是否使用内置 属性 名称或架构名称来指定列。对于显式内置 属性 名称(例如 EntryID),Row(Column) 值作为字符串返回。对于引用代表 PT_BINARY 属性 的名称空间的 属性 名称,行(列)值作为字节数组返回。使用Row.BinaryToString将字节数组转换为字符串。
我正在尝试读取此线程中提到的 DASL 值 PR_LONGTERM_ENTRYID_FROM_TABLE 0x66700102 - get outlook mailitem for message taken from outlook table
我遇到的问题是下面完整示例中代码中的以下行-
string ltEntryid = (string)nextRow["http://schemas.microsoft.com/mapi/proptag/0x66700102".ToString()];
抛出异常"Cannot convert type 'byte[]' to 'string'"
我可能会以错误的方式解决这个问题,所以我正在寻找一些建议。我可以很好地阅读所有其他表格行(示例 - “EntryID(短期),MessageClass,Unread,SenderEmailType)。
const string unReadfilter = "[UnRead] = true";
Outlook.Table table = folder.GetTable(unReadfilter, Outlook.OlTableContents.olUserItems);
// Remove the default column set.
table.Columns.RemoveAll();
// Add columns to the table
table.Columns.Add("Unread");
table.Columns.Add("EntryID");
table.Columns.Add("MessageClass");
table.Columns.Add("SenderEmailType");
table.Columns.Add("SenderEmailAddress");
// PR_LONGTERM_ENTRYID_FROM_TABLE
table.Columns.Add("http://schemas.microsoft.com/mapi/proptag/0x66700102".ToString());
// sort table
table.Sort("Unread", true);
while (!table.EndOfTable)
{
Outlook.Row nextRow = table.GetNextRow();
bool unRead = (bool)nextRow["Unread"];
Debug.WriteLine(unRead);
string msgClass = (string)nextRow["MessageClass"];
Debug.WriteLine(msgClass);
string eId = (string)nextRow["EntryID"];
Debug.WriteLine(eId);
string sEaddr = (string)nextRow["SenderEmailAddress"];
Debug.WriteLine(sEaddr);
string sEtype = (string)nextRow["SenderEmailType"];
Debug.WriteLine(sEtype);
// PR_LONGTERM_ENTRYID_FROM_TABLE ***Exception with the following line***
string ltEntryid = (string)nextRow["http://schemas.microsoft.com/mapi/proptag/0x66700102".ToString()];
Debug.WriteLine(ltEntryid);
if (msgClass.Equals("IPM.Note"))
{
//write to string list
dailyMiInboxList.Add(unRead.ToString());
dailyMiInboxList.Add(msgClass);
dailyMiInboxList.Add(eId);
dailyMiInboxList.Add(sEaddr);
dailyMiInboxList.Add(sEtype);
dailyMiInboxList.Add(sEaddr);
dailyMiInboxList.Add(ltEntryid);
}
}
PT_BINARY 属性 作为字节数组返回,但您将其转换为字符串。如果要将其转换为十六进制字符串,请使用 MAPIFolder.PropertyAccessor.BinaryToString()
.
好的,我在德米特里的帮助下解决了这个问题。
首先将此 dasl 属性 添加到 table -
// PR_LONGTERM_ENTRYID_FROM_TABLE
table.Columns.Add("http://schemas.microsoft.com/mapi/proptag/0x66700102".ToString());
我不应该包括 tostring 所以它应该写成如下-
table.Columns.Add(@"http://schemas.microsoft.com/mapi/proptag/0x66700102");
接下来在 While 循环中,要从字节数组转换 PT_BINARY 属性 使用它来转换行-
string PR_LONGTERM_ENTRYID_FROM_TABLE = "http://schemas.microsoft.com/mapi/proptag/0x66700102";
string ltEntryId = (string)nextRow.BinaryToString(PR_LONGTERM_ENTRYID_FROM_TABLE);
Debug.Print(ltEntryId);
特别是这些评论- • 为表示二进制 (PT_BINARY) 值的给定列返回的值取决于是否使用内置 属性 名称或架构名称来指定列。对于显式内置 属性 名称(例如 EntryID),Row(Column) 值作为字符串返回。对于引用代表 PT_BINARY 属性 的名称空间的 属性 名称,行(列)值作为字节数组返回。使用Row.BinaryToString将字节数组转换为字符串。