在 Microsoft Outlook 中加载时,使用 Redemption API 创建的 PST 文件为空 [英] Created PST file using Redemption API is empty when loaded in Microsoft Outlook

查看:106
本文介绍了在 Microsoft Outlook 中加载时,使用 Redemption API 创建的 PST 文件为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境:我有一个 Windows 控制台应用程序,我正在从命令行运行 exe.下面是我的代码:

Environment: I have a windows console application and I am running the exe from command line. Below is my code:

 static void Main(string[] args)
 {
   CreatePSTUsingRedemption(args[0], args[1]);
 }
 private static void CreatePSTUsingRedemption(string messageFilePath, string pstPath)
 {       
   RDOSession pstSession = new RDOSession();
   RDOPstStore store = null;
   store = pstSession.LogonPstStore(pstPath, 1, "combinedPST");
   //actually there is a loop here to loop through each message files.
   RDOMail rdo_Mail = pstSession.GetMessageFromMsgFile(messageFilePath);
   rdo_Mail.CopyTo(store.IPMRootFolder);
   rdo_Mail.Save();
   store.Save();
   completedCount++;
   Console.WriteLine("FILES_PROCESSED:" + completedCount);
   pstSession.Logoff();
 }

此代码的主要目的是创建一个结合电子邮件 (.msg) 文件的单个 pst 文件.现在,当我运行 exe 时,会在给定位置创建一个 pst 文件,并且它的大小随着代码运行而不断增加.处理完所有消息文件后,应用程序存在.没有任何错误.现在,当我尝试在 Outlook 2013 中加载这个 pst 文件时. Pst 是空的,它的大小也每次减少到 265KB.我认为没有任何进程在使用此 pst,因为我可以将其复制并移动到我想要的任何位置.可能是什么问题?请问有什么建议吗?

Main purpose of this code is to create a single pst file combining email message(.msg) files. Now when I run the exe, a pst file is created in the given location and its size keeps increasing as the code runs. After all the message files are processed application exists. There is no any error. Now, when I try to load this pst file in Outlook 2013. Pst is empty and its size is also reduced to 265KB every time. I don't think any process is using this pst because I can copy and move it anywhere I want. What might be the issue? Any suggestion, please?

更新 1

private static void CreatePSTUsingRedemption(XmlNodeList nodelist, string pstPath)
    {
        System.Diagnostics.Debugger.Launch();
        RDOSession pstSession = null;
        RDOPstStore store = null;
        RDOFolder folder = null;
        RDOMail rdo_Mail = null;
        try
        {
            pstSession = new RDOSession();
            store = pstSession.LogonPstStore(pstPath, 1, Path.GetFileNameWithoutExtension(pstPath));             
            var enumerator = store.IPMRootFolder.Folders.GetEnumerator(); //DELETE DEFAULT FOLDERS
            while (enumerator.MoveNext())
            {
                var defaultFolders = enumerator.Current as RDOFolder;
                    defaultFolders.Delete();
            }
            int completedCount = 0;
            folder = store.IPMRootFolder;
            foreach (XmlNode node in nodelist)
            {
                rdo_Mail = pstSession.GetMessageFromMsgFile(node["FullPath"].InnerText);              
                rdo_Mail.CopyTo(folder);
                rdo_Mail.Save();
                store.Save();
                completedCount++;
                Console.WriteLine("FILES_PROCESSED:" + completedCount);                              
            }            
        }
        finally
        {
            Marshal.ReleaseComObject(rdo_Mail);
            Marshal.ReleaseComObject(folder);
            Marshal.ReleaseComObject(store);
        }
        pstSession.Logoff();
        Marshal.ReleaseComObject(pstSession);
        GC.Collect();
    }

以上是我的实际循环代码.我正在从 xml 文件加载所有电子邮件文件路径.我仍然遇到与上述相同的问题.

Above is my code for the actual loop. I am loading all the email messages file path from an xml file. I still encounter same issue as above.

推荐答案

这表明 PST 存储没有完全刷新到磁盘,Outlook 通过重置 PST 文件来修复"它.

This is an indication that the PST store is not fully flushed to the disk and Outlook "fixes' the PST file by resetting it.

在注销并调用 GC.Collect() 之前,首先尝试显式释放所有 Redemption 对象.如果您有一个循环处理多个文件,请在循环的每一步释放消息.

Try to explicitly release all Redemption objects first before logging off and call GC.Collect(). If you have a loop processing multiple files, release the message on each step of the loop.

 private static void CreatePSTUsingRedemption(string messageFilePath, string pstPath)
 {       
   RDOSession pstSession;
   try
   {
     RDOPstStore store;
     RDOFolder folder;
     RDOMail rdo_Mail;
     pstSession = new RDOSession();
     store = pstSession.LogonPstStore(pstPath, 1, "combinedPST");
     //actually there is a loop here to loop through each message files.
     rdo_Mail = pstSession.GetMessageFromMsgFile(messageFilePath);
     folder = store.IPMRootFolder;
     rdo_Mail.CopyTo(folder);
     rdo_Mail.Save();
     store.Save();
     completedCount++;
     Console.WriteLine("FILES_PROCESSED:" + completedCount);
   }
   finally
   {
     Marshal.ReleaseComObject(rdo_Mail);
     Marshal.ReleaseComObject(folder);
     Marshal.ReleaseComObject(store);
   }
   pstSession.Logoff(); 
   Marshal.ReleaseComObject(pstSession);
   GC.Collect();
 }

这篇关于在 Microsoft Outlook 中加载时,使用 Redemption API 创建的 PST 文件为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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