Search a big (13 GB) Outlook PST file I have an Outlook PST file of a pretty big size (13 GB). For some indexing purpose I needed to scan through the full PST file to get all the PR_SEARCH_KEY and then write into a text file. This recursive procedure is used to loop through all folders and subfolders to get the PR_SEARCH_KEY from each email and non-email item. It took nearly 30 minutes to complete the full scan and writing into the text file.

How can I make this faster, such as for completing the process within 5 minutes?
  Is there any efficiency I'm missing here? I'm very new to Outlook and VB.NET.

Dim dict = New Dictionary(Of String, String)

Sub PrepareIndexing()
    Dim oApp As Outlook.Application
    Dim objName As Outlook.NameSpace
    Dim sFolder As Outlook.Folder        
    oApp = CreateObject("Outlook.Application")
    objName = oApp.GetNamespace("MAPI")
    sFolder = objName.Folders.Item("pstname")

    dict.Clear()

    Call InitIndexing(sFolder)

    For Each d As KeyValuePair(Of String, String) In dict
        Using outputFile As New StreamWriter("E:\" &amp; Convert.ToString("file.txt"), True)
            outputFile.WriteLine(d.Key &amp; "," &amp; d.Value)
        End Using
    Next
    dict.Clear()        
End Sub


Sub InitIndexing(f As Outlook.Folder)
    Dim PropName, skey As String
    Dim oPA As Outlook.PropertyAccessor
    PropName = "http://schemas.microsoft.com/mapi/proptag/0x300B0102" 'Pr_Search_Key

    If f.Folders.Count &gt; 0 Then
        For c = 1 To f.Folders.Count
            Dim Folder As Outlook.Folder = f.Folders.Item(c)
            Dim r As String = Folder.FolderPath
            For Each ml In Folder.Items
                oPA = ml.PropertyAccessor
                skey = oPA.BinaryToString(oPA.GetProperty(PropName))
                If Not dict.ContainsKey(skey) Then
                    dict.Add(skey, r)
                End If
            Next
            Call InitIndexing(Folder)
        Next
    End If
End Sub
I would assume that this
For Each d As KeyValuePair(Of String, String) In dict
    Using outputFile As New StreamWriter(&quot;E:\&quot; &amp; Convert.ToString(&quot;file.txt&quot;), True)
        outputFile.WriteLine(d.Key &amp; &quot;,&quot; &amp; d.Value)
    End Using
Next  

is the bottleneck of your code. You are opening, writing to and closeing the file for each KeyValuePair of the dictionary.
Change it like
Using outputFile As New StreamWriter(&quot;E:\&quot; &amp; Convert.ToString(&quot;file.txt&quot;), True)
    For Each d As KeyValuePair(Of String, String) In dict
            outputFile.WriteLine(d.Key &amp; &quot;,&quot; &amp; d.Value)
    Next
End Using  

and it should be running much faster.
Btw, why do you use Convert.ToString(&quot;file.txt&quot;) ?

InitIndexing()
by changing the condition of the f.Folders.Count to check if Count = 0 you could return early from the Sub and therefor save one level of indentation like so
If f.Folders.Count = 0 Then Exit Sub

For c = 1 To f.Folders.Count
    Dim Folder As Outlook.Folder = f.Folders.Item(c)
    Dim r As String = Folder.FolderPath
    For Each ml In Folder.Items
        oPA = ml.PropertyAccessor
        skey = oPA.BinaryToString(oPA.GetProperty(PropName))
        If Not dict.ContainsKey(skey) Then
            dict.Add(skey, r)
        End If
    Next
    Call InitIndexing(Folder)
Next  

but you have bigger problems here: Naming ! You shouldn't use abbreviations to name things. If you come back to this code in 3 months you won't know the meaning of oPA, r or objName. You should always use meaningful names to name things.