I am new to C#. I am able to code in C# because I am a java programmer, and C# is also Object Oriented. Please bear with me as some of the names of the terminologies that I use here to explain might be of java.
How do I iterate among the subfolders using the folder method in C#? I have initialized the subFolders
object of the method folders
of the class Outlook
to store all the subfolders if there are any. And I am using a for
loop to iterate among them. In the loop, I am trying to initialize a subFolder
object of the folder
method to hold the current iterating folder from the subFolders
object.
I am getting a conversion error while trying to assign the current iterating folder, to the subFolder
object.
Error Message: Cannot implicitly convert type 'Microsoft.Office.Interop.Outlook.MAPIFolder' to 'Microsoft.Office.Interop.Outlook.Folder'. An Implicit conversion exists (are you missing a cast?)
Below is a part of the code:
static void enumerateFolders(Outlook.Folder folder) //Checks if there are sub folders inside the Inbox folder.
{
Outlook.Folders subfolders = folder.Folders;
if (subfolders.Count > 0)
{
for (int i = 0; i < subfolders.Count; i++)
{
Outlook.Folder subFolder = subfolders[i]; //This is where I am getting the error.
iterateMessages(subFolder);
}
}
else
{
iterateMessages(folder);
}
}