[英]How to create a top-level folder in my Outlook using vb.net - VB.NET, Outlook 2013
So as the title says, I am trying to create a top-level folder in my Outlook but I haven't got any success with it. 因此,正如标题所述,我正在尝试在Outlook中创建一个顶层文件夹,但没有获得任何成功。 I've read several tutorials and code snippets but non of them seem to be a success. 我已经阅读了一些教程和代码片段,但似乎都没有成功。
So now i Have this piece of code which creates a folder under the Inbox folder: 所以现在我有了这段代码,可以在“收件箱”文件夹下创建一个文件夹:
Dim objFolder As Outlook.MAPIFolder
Dim objOutlook As Outlook._Application
objOutlook = New Outlook.Application()
objFolder.Folders.Add("Some folder", Outlook.OlDefaultFolders.olFolderInbox)
The question is, how can I create the same folder but then as a top-level folder instead as a sub-folder of the inbox folder. 问题是,如何创建相同的文件夹,然后再将其创建为顶级文件夹,而不是收件箱文件夹的子文件夹。
I already tried to do it like this: 我已经尝试过这样做:
objFolder.Folders.Add("Some folder")
but this didn't work. objFolder.Folders.Add("Some folder")
但这不起作用。
Top folders (root nodes in the navigation pane) are store. 存储顶部文件夹(导航窗格中的根节点)。 If you need to add a new store in the profile you can use the AddStoreEx method of the Namesapace class which adds a Personal Folders file (.pst) in the specified format to the current profile. 如果需要在配置文件中添加新商店,则可以使用Namesapace类的AddStoreEx方法,该方法会将指定格式的个人文件夹文件(.pst)添加到当前配置文件中。 See How to: Add or Remove a Store for more information. 有关更多信息,请参见如何:添加或删除商店 。
In case if you need to create a top-level folder (at the same level with standard folders like Inbox and etc.) you can get the Parent folder object of the Inbox or any other default folder and add a new folder there. 如果您需要创建一个顶级文件夹(与Inbox等标准文件夹位于同一级别),则可以获取Inbox的Parent文件夹对象或任何其他默认文件夹,然后在其中添加一个新文件夹。 For example: 例如:
Dim objFolder As Outlook.MAPIFolder
Dim parentFolder as Outlook.MAPIFolder
Dim objOutlook As Outlook._Application
objOutlook = New Outlook.Application()
myNamespace = objOutlook.GetNamespace("MAPI")
objFolder = myNamespace.GetDefaultFolder(olFolderInbox)
parentFolder = objFolder.Parent
parentFolder.Folders.Add("Some folder", Outlook.OlDefaultFolders.olFolderInbox)
Also you may find the GetRootFolder method of the Store class helpful. 另外,您可能会发现Store类的GetRootFolder方法很有帮助。 It returns a Folder object representing the root-level folder of the Store. 它返回一个Folder对象,该对象代表商店的根目录文件夹。 You can use the GetRootFolder method to enumerate the subfolders of the root folder of the Store. 您可以使用GetRootFolder方法枚举应用商店根文件夹的子文件夹。 Unlike NameSpace.Folders which contains all folders for all stores in the current profile, Store.GetRootFolder.Folders allows you to enumerate all folders for a given Store object in the current profile. 与NameSpace.Folders包含当前配置文件中所有商店的所有文件夹不同,Store.GetRootFolder.Folders允许您枚举当前配置文件中给定Store对象的所有文件夹。
Sub EnumerateFoldersInStores()
Dim colStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oRoot As Outlook.Folder
On Error Resume Next
Set colStores = Application.Session.Stores
For Each oStore In colStores
Set oRoot = oStore.GetRootFolder
Debug.Print (oRoot.FolderPath)
EnumerateFolders oRoot
Next
End Sub
Private Sub EnumerateFolders(ByVal oFolder As Outlook.Folder)
Dim folders As Outlook.folders
Dim Folder As Outlook.Folder
Dim foldercount As Integer
On Error Resume Next
Set folders = oFolder.folders
foldercount = folders.Count
'Check if there are any folders below oFolder
If foldercount Then
For Each Folder In folders
Debug.Print (Folder.FolderPath)
EnumerateFolders Folder
Next
End If
Private Sub CreateNewFolder()
Dim oApp As Outlook.Application = New Outlook.Application
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
Dim InboxFolder As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Dim customFolder As Outlook.MAPIFolder
Try
customFolder = InboxFolder.Folders.Add("Vellaichamy", Outlook _
.OlDefaultFolders.olFolderInbox)
InboxFolder.Folders("Authorcode").Display()
Catch ex As Exception
MessageBox.Show("The following error occurred: " & ex.Message)
End Try
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.