首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将哪些文件连接到pst

将哪些文件连接到pst
EN

Stack Overflow用户
提问于 2020-03-18 10:34:36
回答 2查看 493关注 0票数 0

请告诉我你如何从注册表中获得信息,目前连接的.pst文件列表?

示例: Outlook 2013已经安装,一个存档文件被连接到它- archive.pst。

在注册表中,我通过Powershell获得附加的档案,如下所示。

代码语言:javascript
复制
get-item HKCU:\software\Microsoft\Office\15.0\Outlook\Search | select -expandProperty property | where {$_ -match '.pst$'}

显示了曾经连接过的档案列表:

C:\ user \documve1.pst C:\ user \ user \documve2.pst C:\user\user\ Documents \ archive.pst

但是,archive2.pst和archive1.pst现在没有连接,而是只连接了archive.pst。

如果可能的话,在C #中需要一个实现示例。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-03-20 08:33:49

C#中的解决方案如下所示。这个解决方案对我有效。

代码语言:javascript
复制
using Outlook = Microsoft.Office.Interop.Outlook;

static int Main(string[] args)
{
Outlook.Application app = null;
Outlook.NameSpace ns = null;
Outlook.Store store = null;
Outlook.Stores stores = null;
app = new Outlook.Application();
ns = app.GetNamespace("MAPI");
stores = ns.Stores;
string storeList = string.Empty;
for (int i = 1; i <= stores.Count; i++)
{
store = stores[i];
    storeList += String.Format("{0} {2}",
        //store.DisplayName,
        store.FilePath,
        (store.IsDataFileStore ? ".pst" : ".ost"),
        Environment.NewLine);
    if (store != null)
        Marshal.ReleaseComObject(store);
}
   Console.WriteLine(storeList);
}
票数 0
EN

Stack Overflow用户

发布于 2020-03-18 12:05:28

下面是三个Outlook例程,它们演示了从Outlook中检测哪些存储( PST文件是一种存储类型)的三种不同方法。

很抱歉他们不是C#。我目前没有访问C#的权限。如果内存正常,那么一旦连接到InterOp,C#看起来非常类似于VBA语句。

代码语言:javascript
复制
Sub ListStores1()

  Dim InxStoreCrnt As Integer
  Dim NS As NameSpace
  Dim StoresColl As Folders

  Set NS = Application.GetNamespace("MAPI")
  Set StoresColl = NS.Folders

  For InxStoreCrnt = 1 To StoresColl.Count
    Debug.Print StoresColl(InxStoreCrnt).Name
  Next

End Sub
Sub ListStores2()

 Dim StoresColl As Stores
 Dim StoreCrnt As Store

 Set StoresColl = Session.Stores

 For Each StoreCrnt In StoresColl
   Debug.Print StoreCrnt.DisplayName
 Next

End Sub
Sub ListStores3()

  Dim InxStoreCrnt As Long

  With Application.Session
    For InxStoreCrnt = 1 To .Folders.Count
      Debug.Print .Folders(InxStoreCrnt).Name
    Next
  End With

End Sub
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60737700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档