小编Ram*_*Ali的帖子

无法为此会话加载Outlook数据文件(.pst)

我正在使用Microsoft.Office.Interop.Outlook版本12.0.0.0来读取我的outlook pst文件,但是当编译器到达此代码时, outlookNs.AddStore(pstFilePath); 它会出现"Outlook数据文件(.pst)无法为此会话加载"的异常.我也试过,outlookNs.AddStoreEx(pstFilePath);但错误是相同的....任何sugession?

using System;
using System.Collections.Generic;
using Microsoft.Office.Interop.Outlook;

namespace PSTReader {
    class Program {
        static void Main () {
            try {
                IEnumerable<MailItem> mailItems = readPst(@"C:\temp\PST\Test.pst", "Test PST");
                foreach (MailItem mailItem in mailItems) {
                    Console.WriteLine(mailItem.SenderName + " - " + mailItem.Subject);
                }
            } catch (System.Exception ex) {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }

        private static IEnumerable<MailItem> readPst(string pstFilePath, string pstName) {
            List<MailItem> mailItems = new List<MailItem>();
            Application app = new Application();
            NameSpace outlookNs = app.GetNamespace("MAPI");
            // Add PST file …
Run Code Online (Sandbox Code Playgroud)

c# outlook

6
推荐指数
1
解决办法
1606
查看次数

捕获Outlook 2013发送事件

我正在开发一个应该捕获Outlook 2013 Send事件的应用程序.我使用C#项目来完成所需的任务.

特别是我使用以下代码来完成这项任务

public Outlook.Application OutlookApplication;
public Outlook.Inspectors OutlookInspectors;
public Outlook.Inspector OutlookInspector;
public Outlook.MailItem OutlookMailItem;
public delegate void ApplicationEvents_11_ItemSendEventHandler(object Item, ref bool Cancel);

applicationObject = application;
addInInstance = addInInst;
OutlookApplication = application as Outlook.Application;
OutlookInspectors = OutlookApplication.Inspectors;
OutlookInspectors.NewInspector += new InspectorsEvents_NewInspectorEventHandler(OutlookInspectors_NewInspector);
OutlookApplication.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(OutlookMailItem_Send);

string strchkTo = OutlookMailItem.To;
string strchk = "hello Welcome to c#";

OutlookInspector = (Outlook.Inspector)Inspector;
if (Inspector.CurrentItem is Outlook.MailItem)
{
   OutlookMailItem = (Outlook.MailItem)Inspector.CurrentItem;
}
Run Code Online (Sandbox Code Playgroud)

c# vsto

5
推荐指数
1
解决办法
7659
查看次数

标签 统计

c# ×2

outlook ×1

vsto ×1