Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Outlook邮件项目中设置自定义标题_C#_Visual Studio 2010_Outlook_Vsto_Outlook Addin - Fatal编程技术网

C# 在Outlook邮件项目中设置自定义标题

C# 在Outlook邮件项目中设置自定义标题,c#,visual-studio-2010,outlook,vsto,outlook-addin,C#,Visual Studio 2010,Outlook,Vsto,Outlook Addin,我正在使用outlook加载项,需要在其中设置自定义标题。我正在使用VS2010进行开发 我正在尝试以下代码,但它似乎不起作用 private void AddUserProperty(Outlook.MailItem mail, string folderEmailId) { Outlook.PropertyAccessor mailPropertyAccessor = null; try { if (string.IsNullOrEmpty(fol

我正在使用outlook加载项,需要在其中设置自定义标题。我正在使用VS2010进行开发

我正在尝试以下代码,但它似乎不起作用

private void AddUserProperty(Outlook.MailItem mail, string folderEmailId)
{

    Outlook.PropertyAccessor mailPropertyAccessor = null;
    try
    {

        if (string.IsNullOrEmpty(folderEmailId))
             return;

        mailPropertyAccessor = mail.PropertyAccessor;
        mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-WorksiteFolderEmailId", folderEmailId);

        mail.Save();

        try
        {
             MessageBox.Show("Existing :" + mail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-WorksiteFolderEmailId"));
        }
        catch (System.Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
   }
   catch (System.Exception ex)
   {
        Logger.Error(ex);
        MessageBox.Show(ex.Message);
   }
   finally
   {
        if (mailPropertyAccessor != null)  
            Marshal.ReleaseComObject(mailPropertyAccessor);
   }
}

保存邮件项目后,我试图获取相同的项目以进行验证,但它引发了一个异常,表示找不到属性。

我认为您的代码没有问题,尽管直接获取对属性Accessor的引用是不必要的。尝试:

    string prop = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-WorksiteFolderEmailId";
    mail.PropertyAccessor.SetProperty(prop, folderEmailId);

    mail.Save();

您没有使用mailPropertyAccessor设置任何内容。如果使用OutlookSpy查看邮件(单击IMessage按钮),您是否看到该属性?