无法从outlook 2010 Session.DefaultStore对象获取规则

时间:2015-02-16 06:17:48

标签: c# outlook

我使用以下代码来获取Outlook 2010规则。但它抛出的异常是:

"This store does not support rules. Could not complete the operation."

我正在使用控制台应用程序获取Outlook规则。

public void removeRules(MSOutlook.Application app)
{
  Console.WriteLine(" in removeRules ");
  string ruleName = "SvcForeRule";
  try
  {
    // Get Rules from Session.DefaultStore object 
    foreach (MSOutlook.Rules rules in app.Session.DefaultStore.GetRules())
    {
      Console.WriteLine(" rules count : " + rules.Count);
      for (int i = 1; i <= rules.Count; i++)
      {
        MSOutlook.Rule rule1 = rules[i];
        if (rule1.Name == ruleName)
        {
          Console.WriteLine(" rules Name  : " + rule1.Name);
          rules.Remove(i);
          Marshal.ReleaseComObject(rule1);
          break;
        }
        Marshal.ReleaseComObject(rule1);
      }
    }
  }
  catch (Exception ex)
  {
    Console.WriteLine("Exception in remove rules : " + ex.Message);
  }
}

1 个答案:

答案 0 :(得分:1)

哪行代码会产生异常?您是否尝试调试代码?

首先,确保安装了Outlook 2010的所有最新更新和Service Pack。

然后尝试更改以下行代码:

app.Session.DefaultStore.GetRules

app.Session.Stores(1).GetRules

This store does not support rule - MS Outlook 2010论坛帖子描述了完全相同的问题。