Ivan
Ivan

Reputation: 1

Outlook which files are connected pst

Please tell me how you can get information from the registry, the list of connected .pst files at the moment?

Example: Outlook 2013 is installed, an archive is connected to it - archive.pst.

From the registry I get the attached archives as follows through Powershell.

get-item HKCU:\software\Microsoft\Office\15.0\Outlook\Search | select -expandProperty property | where {$_ -match '.pst$'}

A list of archives that have ever been connected is displayed:

C: \ users \ user \ Documents \ archive1.pst
C: \ users \ user \ Documents \ archive2.pst
C: \ users \ user \ Documents \ archive.pst

But archive2.pst and archive1.pst are not connected now, but only archive.pst is connected.

If possible, an implementation example is desirable in C #.

Upvotes: 0

Views: 1003

Answers (2)

Ivan
Ivan

Reputation: 1

The solution in C # will be as follows. This solution worked for me.

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);
}

Upvotes: 0

Tony Dallimore
Tony Dallimore

Reputation: 12413

Below are three Outlook VBA routines that demonstrate three different ways of detecting which stores (A PST file is a type of store) are accessible from Outlook.

Sorry they are not C#. I do not currently have access to C#. If memory serves, once you are connected to the InterOp, the C# looks very similar to the VBA statements.

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

Upvotes: 1

Related Questions