本文整理汇总了C#中Web.SetHomePage方法的典型用法代码示例。如果您正苦于以下问题:C# Web.SetHomePage方法的具体用法?C# Web.SetHomePage怎么用?C# Web.SetHomePage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.SetHomePage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
//.........这里部分代码省略.........
示例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: SetWelcomePage
private static void SetWelcomePage(Web web, Microsoft.SharePoint.Client.File pageFile)
{
if (!web.IsPropertyAvailable("RootFolder"))
{
web.Context.Load(web.RootFolder);
web.Context.ExecuteQueryRetry();
}
if (!pageFile.IsPropertyAvailable("ServerRelativeUrl"))
{
web.Context.Load(pageFile, p => p.ServerRelativeUrl);
web.Context.ExecuteQueryRetry();
}
var rootFolderRelativeUrl = pageFile.ServerRelativeUrl.Substring(web.RootFolder.ServerRelativeUrl.Length);
web.SetHomePage(rootFolderRelativeUrl);
}
示例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: 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))
//.........这里部分代码省略.........
示例6: 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);
// Check if this is not a noscript site as we're not allowed to update some properties
bool isNoScriptSite = web.IsNoScriptSite();
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.ExecuteQueryRetry();
}
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);
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)
{
//.........这里部分代码省略.........
示例7: 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;
File file = null;
try
{
file = web.GetFileByServerRelativeUrl(url);
web.Context.Load(file);
web.Context.ExecuteQueryRetry();
}
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);
string welcomePageUrl = string.IsNullOrEmpty(web.RootFolder.WelcomePage) ? "" : UrlUtility.Combine(web.ServerRelativeUrl, web.RootFolder.WelcomePage);
if (!string.IsNullOrEmpty(welcomePageUrl) && url.Equals(welcomePageUrl, StringComparison.InvariantCultureIgnoreCase))
web.SetHomePage(string.Empty);
file.DeleteObject();
web.Context.ExecuteQueryRetry();
this.AddPage(web, url, page, parser);
}
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);
this.AddPage(web, url, page, parser);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
}
}
if (page.WelcomePage)
{
var rootFolderRelativeUrl = url.Substring(web.ServerRelativeUrl.Length + 1);
web.SetHomePage(rootFolderRelativeUrl);
}
if (page.WebParts != null & page.WebParts.Any())
{
this.AddWebParts(web, page, parser);
}
if (page.Security != null)
{
file = web.GetFileByServerRelativeUrl(url);
web.Context.Load(file.ListItemAllFields);
web.Context.ExecuteQueryRetry();
file.ListItemAllFields.SetSecurity(parser, page.Security);
}
}
}
return parser;
}