Mid Mid - 9 months ago 55
Vb.net Question

VSTO Outlook: Cannot find subfolders of shared inbox

I am trying to move mails from any folder to a very specific subfolder of a shared inbox. After trying many different things that did not work I tried to loop through every single folder in the inbox und check if it has the name I am looking for. When I try moving the mailitem, I get the message that the element could not be moved. After searching a little bit longer for the cause I found out, that apparently no folder inside of my inbox exist and the for each loop exits without checking a single entry. So how am I supposed to access a specific subfolder which i only know the name of?

Relevant code:

Private Const destFolder = "myfoldername"

Public Function MoveMail()
SelectedItems = Globals.ThisAddIn.Application.ActiveExplorer.Selection
For Each Item In SelectedItems
Call MoveSelectedMail(Item)
Next Item
End Function

Function MoveSelectedMail(Item As Outlook.MailItem)
End Function

Function GetFolderToMove(ByVal FolderName As String) As Outlook.Folder
Dim NS As Outlook.NameSpace
Dim objOwner As Outlook.Recipient
NS = Globals.ThisAddIn.Application.GetNamespace("MAPI")
objOwner = NS.CreateRecipient("NameofSharedMailbox")

If objOwner.Resolved Then
Dim inbox As Outlook.Folder
inbox = NS.GetSharedDefaultFolder(objOwner, OlDefaultFolders.olFolderInbox)
For Each folder As Outlook.Folder In inbox.Folders
If folder.Name = FolderName Then
Return folder
End If
Next folder
End If
End Function

This is the code I used in VBA but did not work when I started trying to do the same thing as VSTO addin:

Function GetFolderToMove(ByVal FolderPath As String) As Outlook.Folder
Dim NS As Outlook.NameSpace
Dim objOwner As Outlook.Recipient
Set NS = Application.GetNamespace("MAPI")
Set objOwner = NS.CreateRecipient("NameofSharedMailbox")

If objOwner.Resolved Then
Set GetFolderPath = NS.GetSharedDefaultFolder(objOwner, olFolderInbox).Folders(destFolder)
End If
End Function

What I tried but did not help me solve this problem:

  • Tried returning only the shared inbox and this worked, however, the inbox is not the folder I want to move the mails to.

In short: I am trying to move a mail to a subfolder of a shared inbox but there seem to be no subfolders according to the error messages.

Hoping you can help me.

My Problem might be a little bit out of place as it seems that there might be a problem with the permissions my outlook account has. If the problem is going to be resolved that way, I will update this thread and close ist.

Mid Mid
Answer Source

I solved it - I am not entirely sure how exactly this could have happened but it certainly had to do with the permissions I had.