Files
console_spo_utils/library_spo_utils/Services/WebpartService.cs
T
2023-06-21 10:38:57 +02:00

39 lines
1.2 KiB
C#

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<WebpartService> logger;
private readonly ISharePointAuthenticationManager authMgr;
private readonly ISiteOptions siteOptions;
public WebpartService(
ILogger<WebpartService> 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");
}
}
}
}