Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.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#_Vba_Outlook_Vsto_Outlook Addin - Fatal编程技术网

C# Outlook加载项-存储和查找数据作为隐藏存储项

C# Outlook加载项-存储和查找数据作为隐藏存储项,c#,vba,outlook,vsto,outlook-addin,C#,Vba,Outlook,Vsto,Outlook Addin,我想在Outlook中创建一个“本地数据库”,以隐藏的形式存储一些辅助数据 在研究对象模型之后,我发现了StorageItem对象,这看起来很有希望 我设法存储了一些行,并通过它们唯一的主题查找它们,但是,我在迭代StorageItems时遇到了问题。它在对象模型中表示,StorageItem对象没有可用的直接迭代器,但我可以从相同的文件夹中查询一个表,该文件夹将包含StorageItems 该表最终将包含5个项目,其中没有一个看起来像我存储的项目 以下是我当前用于插入带有一些自定义属性的Sto

我想在Outlook中创建一个“本地数据库”,以隐藏的形式存储一些辅助数据

在研究对象模型之后,我发现了StorageItem对象,这看起来很有希望

我设法存储了一些行,并通过它们唯一的主题查找它们,但是,我在迭代StorageItems时遇到了问题。它在对象模型中表示,StorageItem对象没有可用的直接迭代器,但我可以从相同的文件夹中查询一个表,该文件夹将包含StorageItems

该表最终将包含5个项目,其中没有一个看起来像我存储的项目

以下是我当前用于插入带有一些自定义属性的StorageItems的代码:

public static void InsertStorageItem(String UniqueID, String Name, String Address) 
{
    Outlook.NameSpace ns = null;
    Outlook.Folder tasksFolder = null;

    ns = outlookApp.Session;
    tasksFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks) as Outlook.Folder;

    Outlook.StorageItem OIEDBTask = tasksFolder.GetStorage(UniqueID, Microsoft.Office.Interop.Outlook.OlStorageIdentifierType.olIdentifyBySubject);

    if (OIEDBTask.Size == 0)
    {
        OIEDBTask.UserProperties.Add("uniqueid", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);
        OIEDBTask.UserProperties.Add("name", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);
        OIEDBTask.UserProperties.Add("address", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);
    }

    //assign values to custom properties
    OIEDBTask.UserProperties["uniqueid"].Value = UniqueID;
    OIEDBTask.UserProperties["name"].Value = Name;
    OIEDBTask.UserProperties["address"].Value = Address;

    OIEDBTask.Save();
}
以下是我查询数据的方式:

public static dynamic QueryStorageItem() 
{
    List<dynamic> QueryResults = new List<dynamic>();
    Outlook.NameSpace ns = null;
    Outlook.Folder tasksFolder = null;
    Outlook.Table ResultTable = null;

    ns = outlookApp.Session;
    tasksFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks) as Outlook.Folder;

    String Filter = "[LastModificationTime] > '5/1/2005'";  //tried removing the filter, but it didn't help. the comparison date is very old, so it should always give back some data
    ResultTable = tasksFolder.GetTable(Filter, Outlook.OlTableContents.olHiddenItems);

    while(!ResultTable.EndOfTable)  //tried a do-while structure also, didn't work.
    {
        Outlook.Row resultRow = ResultTable.GetNextRow();
        QueryResults.Add(resultRow.GetValues()); //the GetValues() function will give me an array with 5 objects in it, that are very different than my StorageItems
    }

    return QueryResults;
}
这不起作用,在阅读了一点之后,我得出结论,这可能不起作用,因为它们是自定义用户属性,过滤应该只对Outlook项目的内置属性起作用,例如LastModificationTime和其他

但是,即使没有过滤,我从GetTable函数返回的数据集也没有用处。(因此我无法遍历这些行,它们也不表示我插入的任何数据甚至结构)

有没有可能有人能找到更好的解决方案

我的主要工作是存储一些用户看不见的辅助数据。如果这不是解决方案,那么我将不得不创建任务而不是StorageItems。

从MAPI的角度来看,存储(也称为关联)项只是常规邮件(如果单击IMAPIFolder按钮并转到“关联内容”选项卡,您可以在中看到它们),这只是因为OOM决定以非常不同的方式公开它们。OOM中的存储项并不是真正设计用来搜索的——其思想是,您可以通过主题或消息类创建/打开您的私人项,而不关心或触摸您一无所知的其他存储项

我能想到的一个技巧是使用地址本身(例如“IPM.Note”)构造消息类。user@domain.demo),并在打开存储项时指定该消息类


如果您真的想搜索相关的目录,扩展MAPI(C++或Delphi)或可能是您唯一的选择。赎回以公开常规项目的相同方式公开相关项目,即..
HiddentItems
vs.
项目
。然后,您可以使用。
Find/FindNext/Restrict/MAPITable.ExecSQL

进行搜索,如果没有关于StorageItem的任何帮助,我将尝试以下操作。我将使用
Session.Stores.Item(1).FilePath
获取保存存储(pst和ost文件)的文件夹。你可以使用任何文件夹,但我觉得这个文件夹更整洁。我会在所选文件夹中创建一个Excel工作簿,并将我的机密数据存储在该文件夹中。Excel将为您提供所需的所有功能。@Laurent:事实上,我发现Outlook有一个解决方案模块@SMeaden,我不明白您在问什么。再次感谢您非常详细的回答,以及您花时间回答我的问题。我可以放心地说,整个Outlook开发社区都非常感谢您的工作!最后,我将“数据库”作为任务存储在子文件夹中,将所有自定义数据放入自定义UserProperties(有点隐藏),并使用事件处理程序“保护”任务,因此最终用户将无法更改它们。我这样做是因为我真的被StorageItems困住了,我需要尽快存储。我会试着在事后寻找救赎。
String Filter = "[address] = 'certain value'";