title: Accessing Outlook ost file
body: <p>I have seen the difference between pst and ost files and currently working on accessing the outlook pst file through the following code given below. 
  Is there any way to use the same code for accessing ost file? Can someone refer me to this?</p>
  
  <pre><code>private DataTable GetInboxItems()
  {
      DataTable inboxTable;
      //try
      //{
      filter = "[ReceivedTime] &gt;= '" + dtpStartDate.Value.ToString("dd/MM/yyyy 12:00 AM")   + "' and [ReceivedTime] &lt;= '" + dtpEndDate.Value.ToString("dd/MM/yyyy  11:59 PM") + "'";
      Outlook.Application outlookApp = GetApplicationObject();
      Outlook.Folder root = outlookApp.Session.DefaultStore.GetRootFolder() as  Outlook.Folder;
      EnumerateFolders(root);
      //string filter = "[ReceivedTime] &gt; '" + dtpStartDate.Value.ToString("dd/MM/yyyy")  + "'";
  
      //inbox
      Outlook.MAPIFolder inboxFolder =  outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
      inboxTable = CreateTable();
      int count = 0;
  
  
      if (inboxFolder.Items.Count &gt; 0)
      {
  
          var restrictedItems = inboxFolder.Items.Restrict(filter);
          restrictedItems.Sort("[ReceivedTime]", true); //descending
          //foreach (var item in inboxFolder.Items)
          foreach (var item in restrictedItems)
          {
              var mail = item as Outlook.MailItem;
              if (mail != null)
              {
                  //try
                  //{
                  DataRow row = inboxTable.NewRow();
                  //row["sn"] = (++count).ToString();
                  row["sn"] = mail.EntryID + " " + mail.ReceivedByEntryID;
                  row["MailType"] = "Inbox";
                  row["SenderName"] = mail.SenderName;
                  row["SenderEmail"] = mail.SenderEmailAddress;
                  row["ReceivedDate"] = mail.ReceivedTime;
                  row["Subject"] = mail.Subject;
                  row["Body"] = mail.Body != null ? (mail.Body.Length &gt; 25 ?  mail.Body.Substring(0, 25) : mail.Body) : null;
                  //row["Body"] = mail.Body != null ? mail.Body : "";
                  row["MailSize"] = mail.Size.ToString();
                  string attachments = null;
                  if (mail.Attachments.Count &gt; 0)
                  {
                      foreach (var attachment in mail.Attachments)
                      {
                          if (((Outlook.Attachment)attachment) != null)
                              //attachments = ((Outlook.Attachment)attachment).FileName +  " " + ((Outlook.Attachment)attachment).Size.ToString() + ", ";
                              attachments += (((Outlook.Attachment)attachment).Size / 1024).ToString() + " KB, ";
                      }
                  }
  
  
                  row["AttachmentCount"] = mail.Attachments.Count;
                  if (attachments != null)
                      row["AttachmentSize"] = attachments.Substring(0, attachments.Length - 2);
  
                  inboxTable.Rows.Add(row);
              }
              //catch (Exception ex)
              //{
  
              //    return null;
              //}
  
          }
      }
  
      return inboxTable;
  }
  </code></pre>