尝试从Outlook表格收件箱

时间:2016-01-27 13:14:49

标签: c# outlook outlook-addin outlook-2010 outlook-redemption

我试图读取此线程中提到的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()];

它抛出异常"无法转换类型' byte []'到'字符串'"

我可能会以错误的方式解决这个问题,所以我正在寻找一些建议。我可以很好地读取所有其他表行(例如" 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);     
    }
 }

2 个答案:

答案 0 :(得分:2)

PT_BINARY属性作为byte数组返回,但是您将它转换为字符串。如果要将其转换为十六进制字符串,请使用MAPIFolder.PropertyAccessor.BinaryToString()

答案 1 :(得分:1)

好吧,我在德米特里的帮助下想到了这一点。

首先将此dasl属性添加到表 -

// 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);

This link was very helpful

特别是这些评论 - •表示二进制(PT_BINARY)值的给定列的返回值取决于是使用内置属性名称还是模式名称来指定列。对于显式内置属性名称(例如EntryID),Row(Column)值将作为字符串返回。对于引用表示PT_BINARY属性的命名空间的属性名称,Row(Column)值将作为字节数组返回。使用Row.BinaryToString将字节数组转换为字符串。

相关问题