I creating a provider hosted app that should create a calendarlist in SharePoint. I want it to be a group calendar later on but first I just need to do step 1: Create a calendar.
I cant find any provider hosted guides on how to create a SharePoint-calendar programmatically. I cant find a ListTemplateStyle
for calendar so I tried the event-template, I dont know if its goint to work since there's an error showing up when I try to run this code below:
Uri hostWeb = new Uri(Request.QueryString["SPHostUrl"]);
using (var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWeb, Request.LogonUserIdentity))
{
Web web = clientContext.Web;
ListCreationInformation listCreator = new ListCreationInformation();
listCreator.Title = "CompanyCalendar";
listCreator.Description = "Workcalendar";
listCreator.TemplateType = (int)ListTemplateType.Events; //106 = events
//clientContext.Load(web);
web.Lists.Add(listCreator);
clientContext.ExecuteQuery();
}
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
Line 27: //clientContext.Load(web);
Line 28: web.Lists.Add(listCreator);
Line 29: clientContext.ExecuteQuery();
Line 30:
Line 31: }
It seems like im unauthorized to create a list here for some reason. I have web permission set to full control and my cert looks like this:
<appSettings>
<add key="ClientId" value="ebcb24ca-afbb-4822-8887-f91504f3d25f" />
<add key="ClientSigningCertificatePath" value="C:\Certs\HighTrustSampleCert.pfx" />
<add key="ClientSigningCertificatePassword" value="1234" />
<add key="IssuerId" value="11111111-1111-1111-1111-111111111111" />
</appSettings>
Any idéas?
my second question is: What do I have to learn to make the calendar a group calendar? Any hints?
Thanks