public async Task <IActionResult> Templates([FromBody] string url) { List <SharePointTemplate> results = new List <SharePointTemplate>(); try { Web web = cc.Web; // LCID: https://msdn.microsoft.com/en-us/library/ms912047%28v=winembedded.10%29.aspx?f=255&MSPPError=-2147217396 WebTemplateCollection templates = web.GetAvailableWebTemplates(1033, false); cc.Load(templates); //Execute the query to the server await cc.ExecuteQueryAsync(); // Loop through all the list templates foreach (WebTemplate template in templates) { SharePointTemplate item = new SharePointTemplate() { ID = template.Id, Title = template.Title, Name = template.Name, Description = template.Description }; results.Add(item); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } return(new OkObjectResult(results)); }
public async Task <IActionResult> Templates(string url) { List <SharePointTemplate> results = new List <SharePointTemplate>(); try { // Starting with ClientContext, the constructor requires a URL to the // server running SharePoint. //string url = @"https://dddevops-my.sharepoint.com"; using (ClientContext context = new ClientContext(url)) { context.Credentials = new SharePointOnlineCredentials(_username, _password); Web web = context.Web; // LCID: https://msdn.microsoft.com/en-us/library/ms912047%28v=winembedded.10%29.aspx?f=255&MSPPError=-2147217396 WebTemplateCollection templates = web.GetAvailableWebTemplates(1033, false); context.Load(templates); //Execute the query to the server await context.ExecuteQueryAsync(); // Loop through all the list templates foreach (WebTemplate template in templates) { SharePointTemplate item = new SharePointTemplate() { ID = template.Id, Title = template.Title, Name = template.Name, Description = template.Description }; results.Add(item); } } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } return(new OkObjectResult(results)); }