Accessing Outlook ost file
c#, outlook
Solution
You need to educate yourself on what OST/PST is as the access to them is not much different, both are Store objects so they have the same interface.
Try this sources for a start and experiment yourself as it's the best way to understand how stuff works.
http://en.wikipedia.org/wiki/Personal_Storage_Table
http://msdn.microsoft.com/en-us/library/bb609139(v=office.14).aspx
http://msdn.microsoft.com/en-us/library/ff184648(v=office.14).aspx
http://msdn.microsoft.com/en-us/library/bb208208(v=office.12).aspx
http://www.c-sharpcorner.com/UploadFile/rambab/OutlookIntegration10282006032802AM/OutlookIntegration.aspx
Problem
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? ``` private DataTable GetInboxItems() { DataTable inboxTable; //try //{ filter = "[ReceivedTime] >= '" + dtpStartDate.Value.ToString("dd/MM/yyyy 12:00 AM") + "' and [ReceivedTime] <= '" + 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] > '" + 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 > 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 > 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 > 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; } ```