【问题标题】:Creating AppointmentItems in shared calendars - object not found exception在共享日历中创建 AppointmentItems - 找不到对象异常
【发布时间】: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.CreateRecipientNameSpace.GetShareDefaultFolder 创建并稍后解决它,但是我尝试过的每种组合都以完全相同的方式失败。我觉得我错过了一些愚蠢的东西。

【问题讨论】:

  • 该错误表示无法找到顶级(存储)文件夹。你确定这就是 Outlook 显示该邮箱的方式吗?如果您遍历 NS.Folders 集合,您会看到哪些商店名称?

标签: vb.net outlook office-interop


【解决方案1】:

能够让这个工作(FeelsGoodMan)。当我发现Outlook.NameSpace.GetFolderFromID 时,我放弃了以以前的方式获取日历文件夹的想法。 EntryID 显然是 Outlook 对象的唯一标识符(?不要引用我的话。)通过监视哪些文件夹起作用,我能够获得日历的 EntryID,然后通过使用 GetFolderFromID 我能够得到一个我的代码中的工作文件夹。

Public Sub AddAppointment()
    Const ENTRYID As String = "IdIGotFromWatch"
    Try
        Dim Application As Outlook.Application = New Outlook.Application
        Dim NS As Outlook.NameSpace = Application.GetNamespace("MAPI")
        Dim CalendarFolder As Outlook.Folder
        Dim Appointment As Outlook.AppointmentItem

        CalendarFolder = NS.GetFolderFromID(ENTRYID)

        Appointment = CalendarFolder.Items.Add("IPM.Appointment")

        'with/end with guts that define the appointmentitem here

        Appointment.Save()

        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

编辑:我认为应该说这个解决方案只有在日历/文件夹保持在原处并且​​不移动时才对我有用。如果我理解正确,如果日历被重新定位,EntryID 也会改变。我不确定还有什么会触发 ID 的更改(也许是重命名?等等),但我不明白为什么我不能只更新 ID 以反映将来的更改。这对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多