【问题标题】:[UWP][C#] Create new Calendar on Exchange-type UserDataAccount[UWP][C#] 在 Exchange 类型的 UserDataAccount 上创建新日历
【发布时间】:2017-05-24 12:04:11
【问题描述】:

我想在我的 Enterprise Exchange 帐户中创建一个新日历,但我总是获得相同的“拒绝访问”异常 mscorlib.ni.dll 中出现“System.UnauthorizedAccessException”类型的异常,但未在用户代码中处理 附加信息:访问被拒绝。 (来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))

这是我的代码,为这个问题做了很多简化:

private const string ExchangeActiveSync = "{6833942B-ABDA-4C20-9757-4F9252396BD4}";
UserDataAccountStore userDataAccountStore = await UserDataAccountManager.RequestStoreAsync(UserDataAccountStoreAccessType.AllAccountsReadOnly);

//Read-only access to app user data accounts and system user data accounts.
//AllAccountsReadOnly = 0,
//Read/write access to the current app's user data accounts.
//AppAccountsReadWrite = 1
//So AllAccountsReadWrite is missing :(

IReadOnlyList<UserDataAccount> listUserAccounts = await userDataAccountStore.FindAccountsAsync();

string accountId= (from account in listUserAccounts where account.DeviceAccountTypeId.Equals(ExchangeActiveSync) select account.Id).FirstOrDefault();
//accountId = "29,0,af";
string calendarName = Package.Current.DisplayName;
//calendarName = "Test Calendar"

AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadWrite);

var calendar = await appointmentStore.CreateAppointmentCalendarAsync(calendarName, accountId);
//Here the exception is thrown

calendar.OtherAppReadAccess = AppointmentCalendarOtherAppReadAccess.Full;
calendar.OtherAppWriteAccess = AppointmentCalendarOtherAppWriteAccess.None;
await calendar.SaveAsync();

我还在 package.appxmanifest 中添加了必要的受限功能

<rescap:Capability Name="userDataSystem" />
<rescap:Capability Name="userDataAccountsProvider" />
<rescap:Capability Name="appointmentsSystem" />

我认为主要问题在于 UserDataAccountStoreAccessType 枚举。这里我们错过了“AllAccountsReadWrite”值(就像在日历访问类型中一样)。我认为这是一个巨大的限制。为什么我无法为帐户创建自定义日历?

我注意到这个限制也在系统日历应用程序中,太糟糕了:(

有什么解决办法吗?

非常感谢您的支持。

最好的问候,

弗拉维奥

【问题讨论】:

    标签: c# calendar uwp exchange-server


    【解决方案1】:

    我想在我的 Enterprise Exchange 帐户中创建一个新日历,但我总是获得相同的“访问被拒绝”异常 mscorlib.ni.dll 中出现“System.UnauthorizedAccessException”类型的异常,但未在用户代码中处理附加信息:访问被拒绝。 (来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))

    您已使用AppointmentStoreAccessType.AllCalendarsReadWrite 访问约会商店。然后您使用CreateAppointmentCalendarAsync(calendarName, accountId) 方法创建日历。但是您的帐户是ReadOnly。所以它会抛出“拒绝访问”的异常。

    如果您想在一个现有的 Exchange 帐户中创建一个新日历,通过我这边的测试,目前是不允许的。如果您想在属于邮件帐户的现有日历中创建新约会,请参考以下代码。

    IReadOnlyList<AppointmentCalendar> appointmentCalendars = await appointmentStore.FindAppointmentCalendarsAsync();
    foreach (AppointmentCalendar calendar in appointmentCalendars)
    {
       if(calendar.DisplayName=="Calendar")
        {
            AppointmentCalendar appointmentcalendar = await appointmentStore.GetAppointmentCalendarAsync(calendar.LocalId);
            await appointmentcalendar.SaveAppointmentAsync(appointment);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 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
      相关资源
      最近更新 更多