SharePoint【学习笔记】-- 设置SharePoint 默认欢迎页面
手动方式:
前提为: SharePoint 网站集 启用Feature: SharePoint Server 发布基础架构
SharePoint 网站 启用Feature: SharePoint Server 发布
由此Feature创建了Pages library,如果相关的Feature没有启用,你将不能看到以上画面,你可以通过固定的页面地址来进行访问。
比如:http://hang:2000/_Layouts/WelcomePage.aspx
使用SharePoint对象模型:
using (SPSite site = new SPSite("http://hang:2000"))
{
using (SPWeb web = site.RootWeb)
{
SPFolder rootFolder = web.RootFolder;
rootFolder.WelcomePage = "/HomePage.aspx"; // 特别注意:无论是在Powershell中还是在C#代码中,主页地址中起始的地方不能使用/
rootFolder.Update();
}
}
使用PowerShell:
$SiteUrl = "http://hang:2000"
$Site = Get-SPWeb -identity $SiteUrl
$RootFolder = $Site.RootFolder;
$RootFolder.WelcomePage = "HomePage.aspx"; // 特别注意:无论是在Powershell中还是在C#代码中,主页地址中起始的地方不能使用/
$RootFolder.Update();
$Site.Dispose()
PS C:\> $rootFolder.WelcomePage="/HomePage.aspx"
Exception setting "WelcomePage":"The WelcomePage property must be a path that
is relative to the folder, and the path cannot contain two consecutive periods
(..)."At line:1char:13+ $rootFolder.<<<<WelcomePage="/HomePage.aspx"+CategoryInfo:InvalidOperation:(:)[],RuntimeException+FullyQualifiedErrorId:PropertyAssignmentException
特别注意:无论是在Powershell中还是在C#代码中,主页地址中起始的地方不能使用/。