【发布时间】:2019-05-01 01:09:44
【问题描述】:
我正在尝试创建一个应用程序,允许用户使用 Outlook Interop 在共享 Outlook 日历上为我们的业务创建约会项目(你是这么说的吗?)。
日历位于我的帐户中,我已授予需要它的每个人的权限。这些用户可以创建和修改日历,而不会从他们真正的 Outlook 客户端中遇到问题。我编写了以下函数,它在我的帐户登录时运行时完美运行。当我注销并进入其他用户帐户之一时,它会引发异常。
Public Sub AddAppointment()
Try
Dim Application As Outlook.Application = New Outlook.Application
Dim NS As Outlook.NameSpace = Application.GetNamespace("MAPI")
Dim RootFolder As Outlook.Folder
Dim CalendarFolder As Outlook.Folder
Dim PlumbingCalendarFolder As Outlook.Folder
Dim Appointment As Outlook.AppointmentItem
RootFolder = NS.Folders("myemail@ourdomain.com") 'exception here
CalendarFolder = RootFolder.Folders("Calendar")
FletcherCalendarFolder = CalendarFolder.Folders("Plumbing Tasks")
Appointment = FletcherCalendarFolder.Items.Add("IPM.Appointment")
'with/end with guts that define the appointmentitem here
Appointment.Save()
MessageBox.Show("An event for this due date was added to the calendar.")
Application = Nothing
Catch ex As Exception
MessageBox.Show("The event for this due date could not be added to the calendar. The following error occurred: " & ex.Message)
End Try
End Sub
当我尝试设置 RootFolder 时抛出异常 - 表示“尝试的操作失败。找不到对象。当日历所有者登录时它工作的事实让我相信我不明白我应该如何从不同的帐户获取文件夹。我接近了吗?我知道收件人对象并使用Outlook.Namespace.CreateRecipient 和NameSpace.GetShareDefaultFolder 创建并稍后解决它,但是我尝试过的每种组合都以完全相同的方式失败。我觉得我错过了一些愚蠢的东西。
【问题讨论】:
-
该错误表示无法找到顶级(存储)文件夹。你确定这就是 Outlook 显示该邮箱的方式吗?如果您遍历 NS.Folders 集合,您会看到哪些商店名称?
标签: vb.net outlook office-interop