【问题标题】:Allowed characters in UserDefinedProperty's Name propertyUserDefinedProperty 的 Name 属性中允许的字符
【发布时间】:2012-10-30 12:42:32
【问题描述】:

我在 Outlook 2010 的文件夹级别添加了一个自定义属性。MAPIFolder(和Folder)对象有一个名为UserDefinedProperties 的属性,可以在其中添加自定义属性,但问题是这些属性不是意味着与他们一起存储价值。作为一个黑客,我通过用等号分隔两者来将属性值存储在名称中,例如我会添加一个UserDefinedProperty,其Name 类似于“MyProperty=123”。

现在的问题是,有时我的属性值包含Name 中不允许的字符。例如,我有一个值为“America/New_York”的属性。 Name 中不允许使用这两个字符(斜杠和下划线),所以我得到了一个例外。

我需要在文件夹级别存储属性值的更好方法,或者在UserDefinedProperty 对象的Name 属性中列出允许的字符,以便我可以做某种替换。

我正在使用 C#、.NET Fx 4.0 和 VSTO。

【问题讨论】:

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


    【解决方案1】:

    我的错。我没有完全阅读异常消息。它明确提到了非法字符。它们是:

    方括号: [和]
    下划线:_
    英镑:#

    如果有人对存储文件夹级别属性有更好的想法,请在此处发布。

    【讨论】:

      【解决方案2】:

      您应该使用StorageItem 来管理文件夹级别的状态。 StorageItems 在用户视图中隐藏,允许您使用 Exchange 邮箱项目保持状态。

      通过StorageItem 使用MessageClass 键保持文件夹状态

      Outlook.StorageItem folderState = folder.GetStorage("IPM.Storage.MyCustomStore", Outlook.OlStorageIdentifierType.olIdentifyByMessageClass);
      if (folderState.Size == 0) // no state exists
      { // save state
        folderState.UserProperties.Add("CustomKey1", Outlook.OlUserPropertyType.olText).Value = "America/New_York";
        folderState.Save();
      }
      else // state exists
      { // read state
        string propVal = folderState.UserProperties["CustomKey1"].Value;
      }
      

      您可以为文件夹using Subject as a key 管理StorageItems,或者在上面的示例中使用MessageClass 作为键。

      【讨论】:

      • 这将是一个很好的解决方案。您能否确认它是否仅适用于 Exchange 邮箱或任何 Outlook 文件夹?
      • 我没有任何非 Exchange 邮箱可以用来测试它 - 请回信告诉我们。如果这不适合你,还有other Outlook storage solutions you may be interested in
      【解决方案3】:

      根据例外情况,名称不能包含特殊字符。但是属性的值可以:

      Outlook.Folder folder = Application.GetNamespace("MAPI").Folders[1] as Outlook.Folder;
                      Outlook.StorageItem storageItem = folder.GetStorage("ABCDE", Outlook.OlStorageIdentifierType.olIdentifyBySubject);
      Outlook.UserProperty property = null;
      foreach (Outlook.UserProperty p in storageItem.UserProperties)
      {
          if (p.Name == "PropertyName")
              property = p;
      }
      if (property == null)
      {
          property = storageItem.UserProperties.Add("PropertyName", Outlook.OlUserPropertyType.olText, false,                                                                Outlook.OlDisplayType.olUser);
                      }
      property.Value = "my_value_can_contain[brackets]";
      storageItem.Save();
      

      【讨论】:

        猜你喜欢
        • 2023-04-08
        • 2021-05-13
        • 2021-07-30
        • 2013-11-15
        • 1970-01-01
        • 2012-11-20
        • 1970-01-01
        • 2010-10-29
        • 1970-01-01
        相关资源
        最近更新 更多