本文整理汇总了C#中Web.AddWebPartToWikiPage方法的典型用法代码示例。如果您正苦于以下问题:C# Web.AddWebPartToWikiPage方法的具体用法?C# Web.AddWebPartToWikiPage怎么用?C# Web.AddWebPartToWikiPage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.AddWebPartToWikiPage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddWikiWebPart
private static void AddWikiWebPart(Web w, string serverRelativeHomepageUrl, string webpartXml, int row, int col, string listTitle, string[] fieldsInView)
{
try
{
List l = w.Lists.GetByTitle(listTitle);
w.Context.Load(l, x => x.RootFolder);
w.Context.ExecuteQuery();
w.AddWebPartToWikiPage(serverRelativeHomepageUrl, new OfficeDevPnP.Core.Entities.WebPartEntity { WebPartXml = string.Format(webpartXml, l.RootFolder.Name) }, row, col, true);
if (fieldsInView != null && fieldsInView.Length > 0)
{
var viewQuery = l.Views.Where(x => x.Hidden);
w.Context.LoadQuery(l.Views.Where(x => x.Hidden));
if (viewQuery != null)
{
var viewHidd = viewQuery.First();
viewHidd.ViewFields.RemoveAll();
foreach (string item in fieldsInView)
{
viewHidd.ViewFields.Add(item);
}
viewHidd.RowLimit = 10;
w.Context.ExecuteQuery();
}
}
}
catch (Exception)
{
throw;
}
}
示例2: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(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.Pages)
{
var url = parser.ParseString(page.Url);
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)
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0_, url);
file.DeleteObject();
web.Context.ExecuteQueryRetry();
web.AddWikiPageByUrl(url);
web.AddLayoutToWikiPage(page.Layout, url);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0__failed___1_____2_,url,ex.Message,ex.StackTrace);
}
}
}
else
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0_, url);
web.AddWikiPageByUrl(url);
web.AddLayoutToWikiPage(page.Layout, url);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0__failed___1_____2_,url, ex.Message,ex.StackTrace);
}
}
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);
}
if (page.WebParts != null & page.WebParts.Any())
{
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.WebPartXml = parser.ParseString(webpart.Contents).Trim(new[] {'\n', ' '});
web.AddWebPartToWikiPage(url, wpEntity, (int) webpart.Row, (int) webpart.Column, false);
}
}
}
}
}
//.........这里部分代码省略.........
示例3: 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.RootFolder.WelcomePage);
foreach (var page in template.Pages)
{
var url = parser.ParseString(page.Url);
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)
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0_, url);
if (page.WelcomePage && url.Contains(web.RootFolder.WelcomePage))
web.SetHomePage(string.Empty);
file.DeleteObject();
web.Context.ExecuteQueryRetry();
web.AddWikiPageByUrl(url);
if (page.Layout == WikiPageLayout.Custom)
{
web.AddLayoutToWikiPage(WikiPageLayout.OneColumn, url);
}
else {
web.AddLayoutToWikiPage(page.Layout, url);
}
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
}
}
}
else
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0_, url);
web.AddWikiPageByUrl(url);
web.AddLayoutToWikiPage(page.Layout, url);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
}
}
if (page.WelcomePage)
{
web.RootFolder.EnsureProperty(p => p.ServerRelativeUrl);
var rootFolderRelativeUrl = url.Substring(web.RootFolder.ServerRelativeUrl.Length);
web.SetHomePage(rootFolderRelativeUrl);
}
if (page.WebParts != null & page.WebParts.Any())
{
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.WebPartXml = parser.ParseString(webpart.Contents.Trim(new[] { '\n', ' ' }));
web.AddWebPartToWikiPage(url, wpEntity, (int)webpart.Row, (int)webpart.Column, false);
}
}
var allWebParts = web.GetWebParts(url);
foreach (var webpart in allWebParts)
{
parser.AddToken(new WebPartIdToken(web, webpart.WebPart.Title, webpart.Id));
//.........这里部分代码省略.........
示例4: 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.Pages)
{
var url = page.Url.ToParsedString();
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.AddWikiPageByUrl(url);
web.AddLayoutToWikiPage(page.Layout, url);
}
}
else
{
web.AddWikiPageByUrl(url);
web.AddLayoutToWikiPage(page.Layout, url);
}
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);
}
if (page.WebParts != null & page.WebParts.Any())
{
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.WebPartXml = webpart.Contents.ToParsedString().Trim(new[] {'\n', ' '});
web.AddWebPartToWikiPage(url, wpEntity, (int)webpart.Row, (int)webpart.Column, false);
}
}
}
}
}
示例5: AddListViewWebPartToPage
private static void AddListViewWebPartToPage(ClientContext ctx, Web web, string listTitle, string pageName, int row, int col)
{
List list = web.GetListByTitle(listTitle);
ctx.Load(list, l => l.Id, l => l.Title);
ctx.ExecuteQueryRetry();
OfficeDevPnP.Core.Entities.WebPartEntity wp = new OfficeDevPnP.Core.Entities.WebPartEntity
{
WebPartIndex = 2,
WebPartTitle = list.Title,
WebPartZone = "Left", //Not sure if we need this
WebPartXml = String.Format(ListViewWebPartXml, list.Id, list.Title)
};
web.AddWebPartToWikiPage("SitePages", wp, pageName, row, col, true);
}
示例6: ProvisionObjects
//.........这里部分代码省略.........
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0_, url);
web.AddWikiPageByUrl(url);
if (page.Layout == WikiPageLayout.Custom)
{
web.AddLayoutToWikiPage(WikiPageLayout.OneColumn, url);
}
else
{
web.AddLayoutToWikiPage(page.Layout, url);
}
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
}
}
if (page.WelcomePage)
{
web.RootFolder.EnsureProperty(p => p.ServerRelativeUrl);
var rootFolderRelativeUrl = url.Substring(web.RootFolder.ServerRelativeUrl.Length);
web.SetHomePage(rootFolderRelativeUrl);
}
#if !SP2013
bool webPartsNeedLocalization = false;
#endif
if (page.WebParts != null & page.WebParts.Any())
{
if (!isNoScriptSite)
{
var existingWebParts = web.GetWebParts(url);
foreach (var webPart in page.WebParts)
{
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == parser.ParseString(webPart.Title)) == null)
{
WebPartEntity wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = parser.ParseString(webPart.Title);
wpEntity.WebPartXml = parser.ParseString(webPart.Contents.Trim(new[] { '\n', ' ' }));
var wpd = web.AddWebPartToWikiPage(url, wpEntity, (int)webPart.Row, (int)webPart.Column, false);
#if !SP2013
if (webPart.Title.ContainsResourceToken())
{
// update data based on where it was added - needed in order to localize wp title
#if !SP2016
wpd.EnsureProperties(w => w.ZoneId, w => w.WebPart, w => w.WebPart.Properties);
webPart.Zone = wpd.ZoneId;
#else
wpd.EnsureProperties(w => w.WebPart, w => w.WebPart.Properties);
#endif
webPart.Order = (uint)wpd.WebPart.ZoneIndex;
webPartsNeedLocalization = true;
}
#endif
}
}
var allWebParts = web.GetWebParts(url);
foreach (var webpart in allWebParts)
{
parser.AddToken(new WebPartIdToken(web, webpart.WebPart.Title, webpart.Id));
}
}
else
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_Pages_SkipAddingWebParts, page.Url);
}
}
#if !SP2013
if (webPartsNeedLocalization)
{
page.LocalizeWebParts(web, parser, scope);
}
#endif
file = web.GetFileByServerRelativeUrl(url);
file.EnsureProperty(f => f.ListItemAllFields);
if (page.Fields.Any())
{
var item = file.ListItemAllFields;
foreach (var fieldValue in page.Fields)
{
item[fieldValue.Key] = parser.ParseString(fieldValue.Value);
}
item.Update();
web.Context.ExecuteQueryRetry();
}
if (page.Security != null && page.Security.RoleAssignments.Count != 0)
{
web.Context.Load(file.ListItemAllFields);
web.Context.ExecuteQueryRetry();
file.ListItemAllFields.SetSecurity(parser, page.Security);
}
}
}
return parser;
}