访问Outlook OST文件 [英] Accessing Outlook ost file

查看:222
本文介绍了访问Outlook OST文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到pst和ost文件之间的区别,并且目前正在通过下面给出的以下代码来访问Outlook pst文件. 有什么办法可以使用相同的代码访问ost文件吗?有人可以推荐我吗?

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;
}

推荐答案

您需要对OST/PST进行了解,因为对它们的访问没有太大区别,两者都是

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

这篇关于访问Outlook OST文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆