选择子文件夹(如果有)

时间:2011-11-21 12:37:28

标签: vb.net outlook directory

我想验证子文件夹是否存在,然后选择这些子文件夹。

我选择了一个getDefaultfolder的文件夹,例如:

' INBOX 
siFolder = Ctype(ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox), Outlook.Folder)
' SENT ITEMS 
siFolder = Ctype(ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail), Outlook.Folder)
etc ... 

Where ... 
app = New Outlook.Application()
ns = app.Session

它工作正常,但我看不到是否有现有的子文件夹,我不知道如何选择它们。

1 个答案:

答案 0 :(得分:0)

 Private Sub  CreateNewFolder()
        Dim oApp As Outlook.Application = New Outlook.Application
        Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
        Dim InboxFolder As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        Dim customFolder As Outlook.MAPIFolder
        Try
            For i = 1 To InboxFolder.Folders.Count
                If InboxFolder.Folders.Item(i).Name = "Vellaichamy" Then
                    Exit Sub
                End If
            Next
            customFolder = InboxFolder.Folders.Add("Vellaichamy", Outlook _
           .OlDefaultFolders.olFolderInbox)
            InboxFolder.Folders("Vellaichamy").Display()
        Catch ex As Exception
            MessageBox.Show("The following error occurred: " & ex.Message)
        Finally
            ' Clean up.
            oApp = Nothing
            oNS = Nothing
            InboxFolder = Nothing
            customFolder = Nothing
        End Try
    End Sub