using library_spo_utils.Interfaces.Services; using Microsoft.Extensions.Logging; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.WebParts; namespace library_spo_utils.Services { internal class WebpartService : IWebpartService { private readonly ILogger logger; private readonly ISharePointAuthenticationManager authMgr; private readonly ISiteOptions siteOptions; public WebpartService( ILogger logger, ISharePointAuthenticationManager authMgr, ISiteOptions siteOptions) { this.logger = logger; this.authMgr = authMgr; this.siteOptions = siteOptions; } public void AddWebPart(Web web, LimitedWebPartManager mgr, string xmlSchema, string listName, string zoneName, int zoneId) { try { WebPartDefinition def = mgr.ImportWebPart(xmlSchema); def.WebPart.Hidden = false; mgr.AddWebPart(def.WebPart, zoneName, zoneId); mgr.Context.ExecuteQuery(); } catch (Exception ex) { logger.LogError(ex, "Project Years"); } } } }