outlook哪些文件连接pst
Outlook which files are connected pst
请告诉我如何从注册表中获取信息,当前已连接的 .pst 文件列表?
示例:已安装 Outlook 2013,已连接存档 - archive.pst。
从注册表中,我通过 Powershell 获得了如下附加档案。
get-item HKCU:\software\Microsoft\Office.0\Outlook\Search | select -expandProperty property | where {$_ -match '.pst$'}
显示曾经连接过的存档列表:
C: \ users \ user \ Documents \ archive1.pst
C: \ users \ user \ Documents \ archive2.pst
C: \ users \ user \ Documents \ archive.pst
但是现在archive2.pst和archive1.pst没有连接,只有archive.pst连接了
如果可能,最好有C#的实现示例。
下面是三个 Outlook VBA 例程,演示了三种不同的方法来检测哪些商店(PST 文件是一种商店)可以从 Outlook 访问。
抱歉,它们不是 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 Sub
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);
}
请告诉我如何从注册表中获取信息,当前已连接的 .pst 文件列表?
示例:已安装 Outlook 2013,已连接存档 - archive.pst。
从注册表中,我通过 Powershell 获得了如下附加档案。
get-item HKCU:\software\Microsoft\Office.0\Outlook\Search | select -expandProperty property | where {$_ -match '.pst$'}
显示曾经连接过的存档列表:
C: \ users \ user \ Documents \ archive1.pst C: \ users \ user \ Documents \ archive2.pst C: \ users \ user \ Documents \ archive.pst
但是现在archive2.pst和archive1.pst没有连接,只有archive.pst连接了
如果可能,最好有C#的实现示例。
下面是三个 Outlook VBA 例程,演示了三种不同的方法来检测哪些商店(PST 文件是一种商店)可以从 Outlook 访问。
抱歉,它们不是 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 Sub
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);
}