深入浅出SharePoint——设置站点的默认欢迎页面

手工方式

前提分别在site collection和Site Feature中启用Feature:Office SharePoint Server Publishing。比如两个feature都启用。

由于此Feature创建了Pages library。

如果此Feature没有启用,你在设置欢迎页面的时候,将会收到如下报错信息:The site is not valid. The 'Pages' document library is missing.

如果相关的Feature没有启用,你将不能看到以上画面,你可以通过固定的页面地址来进行访问。比如:http://Mingle/sites/Lab/_Layouts/AreaWelcomePage.aspx

使用SharePoint对象模型:

using (SPSite site = new SPSite("http://sharepoint.com")) 
   {
    using (SPWeb web = site.RootWeb) 
       {
        SPFolder rootFolder = web.RootFolder;
        rootFolder.WelcomePage = "Pages/HomePage.aspx";
        rootFolder.Update();
      }
   }

 

使用PowerShell:

$SiteUrl = "http://sharepoint.com"
$Site = Get-SPWeb -identity $SiteUrl
$RootFolder = $Site.RootFolder;
$RootFolder.WelcomePage = "SitePages/HomePage.aspx";
$RootFolder.Update();
$Site.Dispose()

 

PS C:\> $rootFolder.WelcomePage="/person.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="/person.aspx"+CategoryInfo:InvalidOperation:(:)[],RuntimeException+FullyQualifiedErrorId:PropertyAssignmentException
特别注意:无论是在Powershell中还是在C#代码中,主页地址中起始的地方不能使用/。
posted @ 2013-01-08 16:38  风影极光  阅读(2702)  评论(1编辑  收藏  举报