我想在我的Enterprise Exchange帐户中创建一个新日历,但我总是获得相同的"访问被拒绝"例外 类型' System.UnauthorizedAccessException'的例外情况发生在mscorlib.ni.dll但未在用户代码中处理 其他信息:拒绝访问。 (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枚举中。在这里,我们错过了&#34; AllAccountsReadWrite&#34;值(如在日历访问类型中)。我认为这是一个巨大的限制。为什么我无法为帐户创建自定义日历?
我注意到这个限制也在系统日历应用中,所以很糟糕:(
有什么解决方案吗?
非常感谢您的支持。
最好的问候,
弗拉维奥
答案 0 :(得分:0)
我想在我的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);
}
}