Jad
Jad

Reputation: 41

Searching for a folder in outlook folders

I am working on a VSTO project using C#. I am facing difficulties in an issue which is: I want to search for a specific folder (which I know its name) in all outlook folders that appear to the right (example: Inbox, SentItems, Drafts, ....). Does anyone know how can I achieve this ? N.B: After some research, I found this piece of code: Outlook.Folder inbox =Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)as Outlook.Folder;

foreach (Outlook.MAPIFolder tempFolder in inbox.Folders) {

      if (tempFolder.Name == "Sample Folder")
      {
                     isFind = true;
      } 

}

The issue here is that I have to hard code all folders (i.e. write several foreach loops that iterates through all folders). So, my question again: Is there w way to loop through all Outlook folders without categorizing them as Inbox, SentItems, ...etc ?? Thanks in advance.

Regards,

Upvotes: 0

Views: 383

Answers (1)

user557554
user557554

Reputation: 21

Try the following style:

Folders["Inbox"].Folders["inboxFolderName"]

I've been surrounding it with try/catch as a bit of a bodged way of checking if it exists.

does that help?

Upvotes: 1

Related Questions