title: Retrieve StoreID for MailItem (within Outlook Selection)
body: <p>I need to iterate through the <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.mailitem" rel="nofollow"><code>MailItem</code></a> items within a <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.selection.aspx" rel="nofollow"><code>Selection</code></a> and read their <code>EntryID</code> and <code>StoreID</code> values in order to be able to retrieve the mail items again later (for background processing through Redemption). Is there a way of retrieving the <code>StoreID</code> for a <code>MailItem</code> directly? </p>
  
  <p>I know that it may be retrieved through the <code>StoreID</code> property of its parent <code>Folder</code>; however, this seems quite inefficient, since it must instantiate (and release) the COM object for the parent folder for each item. Is there a more efficient way to achieve this?</p>
  
  <p><strong>Edit</strong>: I cannot use the <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.selection.parent%28v=office.12%29.aspx" rel="nofollow"><code>Selection.Parent</code></a> property since it was only introduced in Outlook 2007, and I need to support Outlook 2003. Additionally, <a href="http://www.outlookcode.com/codedetail.aspx?id=1777" rel="nofollow">Sue Mosher</a> states:</p>
  
  <blockquote>
    <p>The <code>Parent</code> object of a <code>Selection</code> would be an <code>Explorer</code>, so you could use <code>Selection.Parent.CurrentFolder.Store</code>.</p>
  </blockquote>
  
  <p>However, when one performs a search across “All Outlook Items”, it seems that <code>CurrentFolder</code> would always point to a search folder within the main store, which is typically the Exchange mailbox:</p>
  
  <pre><code>\\Mailbox - &lt;username&gt;\search folders\All Outlook Items
  </code></pre>
  
  <p>Since the search may match items in other stores, the <code>CurrentFolder.Store</code> would not necessarily correspond to the store of the selected items, making this approach unreliable.</p>