Visual Studio Development Bookmark and Share   
 index > Visual Studio Tools for Office > How to read items in Public Folder?
 

How to read items in Public Folder?

The Public folder tree is:

Public Folders/All Public Folders/Shared/Today

I would like to read emails from sub folder [Today ]

But I can't see any sub folders of All Public Folders

here is my code:

<em>myApplicationObject = this.Application;
Outlook.Folders myFolders = myApplicationObject.Session.Folders;
// Loop
foreach(Outlook.MAPIFolder myStore in myFolders)
{
   foreach(Outlook.MAPIFolder myFolder in myStore.Folders)
       {
          if(myFolder.Name == "Today")
          {
              //do something
          }
       }
}</em>



Can you give me some advises?
  • Edited byLucky7777 Thursday, August 20, 2009 12:34 AM
  • Edited byLucky7777 Thursday, August 20, 2009 12:36 AM
  • Edited byLucky7777 Thursday, August 20, 2009 12:32 AM
  • Edited byLucky7777 Thursday, August 20, 2009 12:36 AM
  •  
Lucky7777  Thursday, August 20, 2009 12:31 AM


As far as I know, you need to use multiple foreach loops. Here is Code Snippet:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
foreach (Outlook.MAPIFolder rootFolder in this.Application.Session.Folders)
{
if (rootFolder.Name == "Public Folders")
foreach (Outlook.MAPIFolder folder in rootFolder.Folders)
{
if (folder.Name == "All Public Folders")
foreach (Outlook.MAPIFolder folder1 in folder.Folders)
if (folder1.Name == "Shared")
foreach (Outlook.MAPIFolder folder2 in folder1.Folders)
if (folder2.Name == "Today")
{
//do something
goto Outfor;
}
}
}
Outfor:
......
}

If you have any further question, please feel free tolet us know.

Best regards,
Bessie


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bessie Zhao  Tuesday, August 25, 2009 10:19 AM


As far as I know, you need to use multiple foreach loops. Here is Code Snippet:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
foreach (Outlook.MAPIFolder rootFolder in this.Application.Session.Folders)
{
if (rootFolder.Name == "Public Folders")
foreach (Outlook.MAPIFolder folder in rootFolder.Folders)
{
if (folder.Name == "All Public Folders")
foreach (Outlook.MAPIFolder folder1 in folder.Folders)
if (folder1.Name == "Shared")
foreach (Outlook.MAPIFolder folder2 in folder1.Folders)
if (folder2.Name == "Today")
{
//do something
goto Outfor;
}
}
}
Outfor:
......
}

If you have any further question, please feel free tolet us know.

Best regards,
Bessie


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bessie Zhao  Tuesday, August 25, 2009 10:19 AM
Yep, it works!
Thanks.
Lucky7777  Friday, August 28, 2009 8:47 PM
can you please explain how to read mail items in a public folder using VSTO? I try this and the resulting type of the items is "_COM" and not "mailitem" and so I can't do anything with them other than pound the desk in frustration .. any help greatly appreciated, thx.
riix  Thursday, October 15, 2009 9:11 PM
can you please explain how to read mail items in a public folder using VSTO? I try this and the resulting type of the items is "_COM" and not "mailitem" and so I can't do anything with them other than pound the desk in frustration .. any help greatly appreciated, thx.
this is any help:
I'm taking a n attachment like this:

                        // Cast to MailItem
                        Outlook.MailItem myMailItem = (Outlook.MailItem)Item;
                        if (myMailItem != null)
                        {
                            MessageBox.Show(String.Format("Subj: {0}, Attachments {1}", myMailItem.Subject, myMailItem.Attachments.Count));
                            if (myMailItem.Attachments.Count > 0)
                            {
                                for (int i = 1; i <= myMailItem.Attachments.Count; i++)
                                {
                                    myMailItem.Attachments[i].SaveAsFile(@"C:\..." + myMailItem.Attachments[i].FileName);
                                }
                            }
                        }

Lucky7777  Friday, October 16, 2009 6:59 PM

You can use google to search for other answers

Custom Search

More Threads

• Re: Select automatically a pasted Text !
• OLK 2003. Catch the Move mailItem event with mailItem open
• 'System.Windows.Application' does not contain a definition for 'CreateItemFromTemplate'
• Visual Studio Tools fo office
• I want to call a function when a new page in a word comes at runtime or can we trap the page break event at runtime
• Plug-In becomes invisible
• Why does my command bar button’s click event only fires for the first time?
• ThisWorkbook_Open() triggers twice...
• How to start VSTO
• How to detect a new incoming email?