none
Read static subfolders content in outlook using vb.net RRS feed

  • Question

  • Hi All,

    when i was click on outlook addin button and read outlook mapi olfolders like inbox,outbox,drafts,sent items etc is fine.. but  create some static folders like "folder1","folder2" . i am unable to handles read the folder1,folder2 data. please suggest how can i read the static folder content using vb.net

    Thanks In Adv

    Arun.

    Thursday, December 1, 2016 9:34 AM

All replies

  • Hello Arun,

    Where did you create folders? What code do you use for accessing their content?


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Thursday, December 1, 2016 10:38 AM
  • Hi Eugene,

    I am created folders in outoff inbox. 

    this is my code -

      Dim olMailItem As Outlook.MailItem = Nothing

     Dim oapp As Outlook.Application = New Outlook.Application()
            CurrentExplorer = Globals.ThisAddIn.Application.ActiveExplorer()
            Dim mapiNameSpace As Outlook.NameSpace = oapp.GetNamespace("MAPI")

     Dim OIn As Integer = oInbox.Items.Count

    For i As Integer = 1 To OIn

    olMailItem = DirectCast(CurrentExplorer.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Items(i), Outlook.MailItem)

    Next

    Please suggest how to read static folders.

    Thanks in Adv

    Arun

    Thursday, December 1, 2016 1:17 PM
  • Arun,

    I have noticed the following:

    when i was click on outlook addin button

    If you develop an add-in the following line of code is useless.

    Dim oapp As Outlook.Application = New Outlook.Application()

    Instead, you need to use the Application property available in your add-in class.

    Moreover, I'd recommend breaking the chain of property and method calls:

    olMailItem = DirectCast(CurrentExplorer.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Items(i), Outlook.MailItem)

    And declare each property or method call on a separate line of code. Thus, you will be able to release underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about that in the Systematically Releasing Objects article. 


    Dim olInbox As Outlook.MAPIFolder = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)

    Dim olItems as Outlook.Items = olInbox.Items


    To enumerate folders or just find the one you can use the Folders property which returns the Folders collection that represents all the folders contained in the specified Folder. For example, take a look at the following articles:

    How to: Enumerate Folders

    How to: Get a Default Folder and Enumerate Its Subfolders


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Thursday, December 1, 2016 2:56 PM
  • Where are these folders created? Are they on the same level as Inbox etc.? Or are they subfolders of some other folder?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, December 5, 2016 3:31 PM