title: Outlook add-in - Store and look up data as hidden StorageItem
body: <p>I want to create a <em>"local database"</em> in Outlook, by storing some auxiliary data in a hidden form.</p>
  
  <p>After investigating the object model, I found the StorageItem objects, that looked promising.</p>
  
  <p>I managed to store some rows, and also look them up by their unique subject, however, I have trouble iterating through the <strong>StorageItem</strong>s. It says in the object model, that there's no direct iterator available for the StorageItem object, but I could query a <strong>table</strong> from the same folder, that will have the StorageItems.</p>
  
  <p>The table will end up containing 5 items, and none of them look anything like my stored items.</p>
  
  <p>Here's my code that I currently use for inserting the StorageItems with some custom properties: </p>
  
  <pre><code>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();
  }
  </code></pre>
  
  <p>Here's how I would like to query data: </p>
  
  <pre><code>public static dynamic QueryStorageItem() 
  {
      List&lt;dynamic&gt; QueryResults = new List&lt;dynamic&gt;();
      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] &gt; '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;
  }
  </code></pre>
  
  <p>The main idea would be, to use the set up properties of the StorageItems, to use the Filtering, that is given by Outlook: for example, try to find all StorageItems, where the <strong>address</strong> is a certain value.
  Naturally, I would write a similar Filter string: </p>
  
  <pre><code>String Filter = "[address] = 'certain value'";
  </code></pre>
  
  <p>This doesn't work, and after reading up a little bit on it, I came to the conclusion, that it might not work, because they are custom UserProperties, and filtering should only work on built-in properties for the Outlook items, such as <strong>LastModificationTime</strong> and others.</p>
  
  <p>However, even without filtering, the data set that I get back from the <strong>GetTable</strong> function is of no use. (So I can't iterate through the rows, and they don't represent any data or even structure, that I've inserted)</p>
  
  <p>Any chance somebody could guide towards a better solution?</p>
  
  <p>My main scope is, to store some auxiliary data, that is not visible to the user. If this is not the solution, then I would have to create tasks instead of StorageItems.</p>