39 lines
1.2 KiB
C#
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");
|
|
}
|
|
}
|
|
}
|
|
} |