I'm attempting to read the DASL value PR_LONGTERM_ENTRYID_FROM_TABLE 0x66700102 mentioned in this thread - get outlook mailitem for message taken from outlook table
The issue I'm having is with the following line in the code below from the full example below-
string ltEntryid = (string)nextRow["http://schemas.microsoft.com/mapi/proptag/0x66700102".ToString()];
It throws an exception "Cannot convert type 'byte[]' to 'string'"
I might be going about this the wrong way so I'm looking for some advice. I can read all the other tables rows fine (Example- "EntryID(short term), 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);
}
}
OK, I figured this out with Dmitry's help.
First when adding this dasl property to the table -
// PR_LONGTERM_ENTRYID_FROM_TABLE
table.Columns.Add("http://schemas.microsoft.com/mapi/proptag/0x66700102".ToString());
I should've not included the tostring so it should be written as follows-
table.Columns.Add(@"http://schemas.microsoft.com/mapi/proptag/0x66700102");
Next in the While loop, to convert the PT_BINARY property from an array of bytes use this to convert the row-
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);
In particular these comments- • The value returned for a given column representing a binary (PT_BINARY) value depends on whether a built-in property name or a schema name was used to specify the Column. For explicit built-in property names (such as EntryID), the Row(Column) value is returned as a string. For property names referencing a namespace that represent a PT_BINARY property, the Row(Column) value is returned as a byte array. Use Row.BinaryToString to convert the byte array to a string.