请告诉我你如何从注册表中获得信息,目前连接的.pst文件列表?
示例: Outlook 2013已经安装,一个存档文件被连接到它- archive.pst。
在注册表中,我通过Powershell获得附加的档案,如下所示。
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 #中需要一个实现示例。
发布于 2020-03-20 08:33:49
C#中的解决方案如下所示。这个解决方案对我有效。
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);
}发布于 2020-03-18 12:05:28
下面是三个Outlook例程,它们演示了从Outlook中检测哪些存储( PST文件是一种存储类型)的三种不同方法。
很抱歉他们不是C#。我目前没有访问C#的权限。如果内存正常,那么一旦连接到InterOp,C#看起来非常类似于VBA语句。
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 Subhttps://stackoverflow.com/questions/60737700
复制相似问题