本文整理汇总了C#中Web.AddPublishingPage方法的典型用法代码示例。如果您正苦于以下问题:C# Web.AddPublishingPage方法的具体用法?C# Web.AddPublishingPage怎么用?C# Web.AddPublishingPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.AddPublishingPage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPublishingPage
public static void AddPublishingPage(PublishingPage page, ClientContext ctx, Web web)
{
SPPublishing.PublishingPage publishingPage = web.GetPublishingPage(page.FileName + ".aspx");
RemovePublishingPage(publishingPage, page, ctx, web);
web.AddPublishingPage(page.FileName, page.Layout, page.Title, false); //DO NOT Publish here or it will fail if library doesn't enable Minor versions (PnP bug)
publishingPage = web.GetPublishingPage(page.FileName + ".aspx");
Microsoft.SharePoint.Client.File pageFile = publishingPage.ListItem.File;
pageFile.CheckOut();
if (page.Properties != null && page.Properties.Count > 0)
{
ctx.Load(pageFile, p => p.Name, p => p.CheckOutType); //need these values in SetFileProperties
ctx.ExecuteQuery();
pageFile.SetFileProperties(page.Properties, false);
}
if (page.WebParts != null && page.WebParts.Count > 0)
{
Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr = pageFile.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);
ctx.Load(mgr);
ctx.ExecuteQuery();
AddWebpartsToPublishingPage(page, ctx, mgr);
}
List pagesLibrary = publishingPage.ListItem.ParentList;
ctx.Load(pagesLibrary);
ctx.ExecuteQueryRetry();
ListItem pageItem = publishingPage.ListItem;
web.Context.Load(pageItem, p => p.File.CheckOutType);
web.Context.ExecuteQueryRetry();
if (pageItem.File.CheckOutType != CheckOutType.None)
{
pageItem.File.CheckIn(String.Empty, CheckinType.MajorCheckIn);
}
if (page.Publish && pagesLibrary.EnableMinorVersions)
{
pageItem.File.Publish(String.Empty);
if (pagesLibrary.EnableModeration)
{
pageItem.File.Approve(String.Empty);
}
}
if (page.WelcomePage)
{
SetWelcomePage(web, pageFile);
}
ctx.ExecuteQuery();
}
示例2: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser,
ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var context = web.Context as ClientContext;
web.EnsureProperties(w => w.ServerRelativeUrl, w => w.Url);
foreach (PublishingPage page in template.Publishing.PublishingPages)
{
string parsedFileName = parser.ParseString(page.FileName);
string parsedFullFileName = parser.ParseString(page.FullFileName);
Microsoft.SharePoint.Client.Publishing.PublishingPage existingPage =
web.GetPublishingPage(parsedFileName + ".aspx");
if (!web.IsPropertyAvailable("RootFolder"))
{
web.Context.Load(web.RootFolder);
web.Context.ExecuteQueryRetry();
}
if (existingPage != null && existingPage.ServerObjectIsNull.Value == false)
{
if (!page.Overwrite)
{
scope.LogDebug(
CoreResources.Provisioning_ObjectHandlers_PublishingPages_Skipping_As_Overwrite_false,
parsedFileName);
continue;
}
if (page.WelcomePage && web.RootFolder.WelcomePage.Contains(parsedFullFileName))
{
//set the welcome page to a Temp page to allow page deletion
web.RootFolder.WelcomePage = "home.aspx";
web.RootFolder.Update();
web.Update();
context.ExecuteQueryRetry();
}
existingPage.ListItem.DeleteObject();
context.ExecuteQuery();
}
web.AddPublishingPage(
parsedFileName,
page.Layout,
parser.ParseString(page.Title)
);
Microsoft.SharePoint.Client.Publishing.PublishingPage publishingPage =
web.GetPublishingPage(parsedFullFileName);
Microsoft.SharePoint.Client.File pageFile = publishingPage.ListItem.File;
pageFile.CheckOut();
if (page.Properties != null && page.Properties.Count > 0)
{
context.Load(pageFile, p => p.Name, p => p.CheckOutType);
context.ExecuteQueryRetry();
var parsedProperties = page.Properties.ToDictionary(p => p.Key, p => parser.ParseString(p.Value));
pageFile.SetFileProperties(parsedProperties, false);
}
if (page.WebParts != null && page.WebParts.Count > 0)
{
Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr =
pageFile.GetLimitedWebPartManager(
Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);
context.Load(mgr);
context.ExecuteQueryRetry();
AddWebPartsToPublishingPage(page, context, mgr, parser);
}
List pagesLibrary = publishingPage.ListItem.ParentList;
context.Load(pagesLibrary);
context.ExecuteQueryRetry();
ListItem pageItem = publishingPage.ListItem;
web.Context.Load(pageItem, p => p.File.CheckOutType);
web.Context.ExecuteQueryRetry();
if (pageItem.File.CheckOutType != CheckOutType.None)
{
pageItem.File.CheckIn(String.Empty, CheckinType.MajorCheckIn);
}
if (page.Publish && pagesLibrary.EnableMinorVersions)
{
pageItem.File.Publish(String.Empty);
if (pagesLibrary.EnableModeration)
{
pageItem.File.Approve(String.Empty);
}
}
if (page.WelcomePage)
{
SetWelcomePage(web, pageFile);
}
//.........这里部分代码省略.........
示例3: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template)
{
Log.Info(Constants.LOGGING_SOURCE_FRAMEWORK_PROVISIONING, CoreResources.Provisioning_ObjectHandlers_Pages);
var context = web.Context as ClientContext;
if (!web.IsPropertyAvailable("ServerRelativeUrl"))
{
context.Load(web, w => w.ServerRelativeUrl);
context.ExecuteQueryRetry();
}
foreach (var page in template.PublishingPages)
{
var url = String.Format("{0}/Pages/{1}.aspx", web.ServerRelativeUrl, page.PageName);
if (!url.ToLower().StartsWith(web.ServerRelativeUrl.ToLower()))
{
url = UrlUtility.Combine(web.ServerRelativeUrl, url);
}
var exists = true;
Microsoft.SharePoint.Client.File file = null;
try
{
file = web.GetFileByServerRelativeUrl(url);
web.Context.Load(file);
web.Context.ExecuteQuery();
}
catch (ServerException ex)
{
if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")
{
exists = false;
}
}
if (exists)
{
if (page.Overwrite)
{
file.DeleteObject();
web.Context.ExecuteQueryRetry();
web.AddPublishingPage(page.PageName, page.PageLayoutName, page.Title, page.Content, page.Properties, page.Publish);
}
//if (file.CheckOutType == CheckOutType.None)
//{
// file.CheckOut();
//}
}
else
{
web.AddPublishingPage(page.PageName, page.PageLayoutName, page.Title, page.Content, page.Properties, page.Publish);
}
if (page.WelcomePage)
{
if (!web.IsPropertyAvailable("RootFolder"))
{
web.Context.Load(web.RootFolder);
web.Context.ExecuteQueryRetry();
}
var rootFolderRelativeUrl = url.Substring(web.RootFolder.ServerRelativeUrl.Length);
web.SetHomePage(rootFolderRelativeUrl);
}
// Check out the file if needed
if (page.WebParts != null & page.WebParts.Any())
{
if (!exists)
{
file = web.GetFileByServerRelativeUrl(url);
web.Context.Load(file);
web.Context.ExecuteQuery();
}
file.CheckOut();
var existingWebParts = web.GetWebParts(url);
foreach (var webpart in page.WebParts)
{
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == webpart.Title) == null)
{
WebPartEntity wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = webpart.Title;
wpEntity.WebPartIndex = (int)webpart.Order;
wpEntity.WebPartZone = webpart.Zone;
if (!string.IsNullOrWhiteSpace(webpart.ListUrl))
//.........这里部分代码省略.........