Hi everyone,

need some help with outlook. i need to extract information from outlook messages from default folder(inbox) to subfolders(including subfolders of subfolders) but it seems that i'm having problem on calling the folder from the outlook's default pst file. below are the codes i've already tried.

outlookfolder = outlookmapi.Folders(folder_name)
outlookfolder = outlookmapi.Folders("support@domain.com").Folders("domain.com").Folders("Inbox")

is there anything i'm missing. or maybe folder_name is a path in the pst file?
any help or suggestion will be appreciated. XD

thanks in advance.

Dani AI

Generated

For automation you want to treat the Outlook object model as a tree, not a single string path. The expression you tried (e.g. calling Namespace.Folders("support@domain.com").Folders("domain.com").Folders("Inbox")) will only work if each display name exactly matches the store and folder names Outlook exposes. Folder names in Outlook stores often differ (Mailbox display name, "Personal Folders", etc.), so "folder_name" is not a generic path string. Use the Namespace.GetDefaultFolder method to get the default Inbox (or let the user pick a folder), then recurse the MAPIFolder.Folders collection to walk subfolders.

The pattern below shows the essentials in VB.NET: get the default inbox, walk all subfolders, and a helper to resolve a path like "Inbox\Support\Orders" (it removes empty path parts so leading "\" paths from FolderPath work).

Dim app = New Microsoft.Office.Interop.Outlook.Application()
Dim ns = app.GetNamespace("MAPI")
Dim inbox = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
WalkFolders(inbox)

Sub WalkFolders(folder As Microsoft.Office.Interop.Outlook.MAPIFolder)
    ' process folder.Items here
    For Each subF As Microsoft.Office.Interop.Outlook.MAPIFolder In folder.Folders
        WalkFolders(subF)
    Next
End Sub

Function GetFolderByPath(ns As Microsoft.Office.Interop.Outlook.NameSpace, path As String) As Microsoft.Office.Interop.Outlook.MAPIFolder
    Dim parts() As String = path.Split(New Char() {"\"c}, StringSplitOptions.RemoveEmptyEntries)
    Dim cur As Microsoft.Office.Interop.Outlook.MAPIFolder = Nothing
    If parts.Length = 0 Then Return Nothing
    cur = ns.Folders(parts(0))
    For i As Integer = 1 To parts.Length - 1
        If cur Is Nothing Then Return Nothing
        cur = cur.Folders(parts(i))
    Next
    Return cur
End Function

Notes and troubleshooting: to let the user choose a folder use Namespace.PickFolder(). If multiple stores exist enumerate ns.Folders (or ns.Stores/GetRootFolder) to discover the exact top-level names. Use MAPIFolder.FolderPath to inspect real paths. Always run Outlook interop on a desktop client (not as a server/service), handle COM objects carefully (ReleaseComObject/GC) and run in STA. As suggested, manual dragging is fine for one-off sorting, but for automation the above pattern (GetDefaultFolder + recursive traversal or PickFolder + traversal) is the reliable approach for extracting items from the default PST and its nested subfolders.

I am not sure I understand. It seems like you could just start outlook, Hi-lite personal folders and create the folder structure you need. Then Hi-lite inbox and drag the messages from inbox to their respective folders/subfolders>. not sure I understand. It seems like you could just start outlook, Hi-lite personal folders and create the folder structure you need. Then Hi-lite inbox and drag the messages from inbox to their respective folders/subfolders>.

i am automating an outlook here using vb.net and i need to extract items email information from a user chosen folderlist on their outlook default pst.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.