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. - Marked As Answer byBessie ZhaoMSFT, ModeratorFriday, August 28, 2009 5:40 AM
-
| | 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. - Marked As Answer byBessie ZhaoMSFT, ModeratorFriday, August 28, 2009 5:40 AM
-
| | 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 |
|