0

I have created a Custom Default.aspx and through the code you see I can use it as "Home Page".

SPWeb web = osite.OpenWeb("/anotherSite");
SPFolder oFolder = web.RootFolder;
oFolder.WelcomePage = "SitePages/CustomDefault.aspx";

My question is, How can I provision this custom default.aspx to other sites?

Any tips? Can I use a FileStream to "Copy&Paste" the site? Can i use a module to upload/provision the file to new sites?

How would one go about doing this?

Thanks in advance!

  • 2
    First thought is to write a powershell script that loops through all the sites and subsites and uploads the default.aspx page and makes it the homepage for that site/web. – Mike Mar 20 '14 at 15:31
  • When you did a site as you want, maybe an export and then import can help you ? Or save your own homepage as a template, then use it ? (don't blame me if my answer is useless :p), Btw hope this can help – Nico Mar 20 '14 at 15:32
1

You can do this completely declaratively with no custom code. Use a module and set the welcome page via a web property:

<Module Name="SitePages" Url="Lists/Configuration">
    <File Path="SitePages/CustomDefault.aspx" Url="CustomDefault.aspx" Type="GhostableInLibrary" />
  </Module>
 <PropertyBag Url="" ParentType="Folder" RootWebOnly="FALSE" AlwaysCreateFolder="TRUE" xmlns="http://schemas.microsoft.com/sharepoint/">
  <Property Name="vti_welcomepage" Value="SitePages/CustomDefault.aspx" Type="string" />
</PropertyBag>
  • Thanks great tip! works right a way, but since the module is in the my web feature witch is also activated on the root is there a possibility to set some property to like RootWebObly="TRUE", but not on the root!? :) – George Norberg Mar 21 '14 at 9:19
  • 1
    No, there is no "SubWebOnly" attribute I'm aware of. If you do not want the home page on the root web, do not activate it there. You might need to break it out into its own feature if that makes sense. – Derek Gusoff Mar 21 '14 at 11:01
1

Use the module to provision the file and create feature and then write the code in feature activated event to set the welcome page of the site.

1

Here is a snippet of Powershell code that you could run ( I didn't test this )

$siteUrl = "https://yoursite.com"
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication

foreach($site in $spWebApp.Sites) 
{     
        $web = $site.RootWeb
        write-host $web.Url

        $folder = $web.GetFolder("\SitePages")
        $fileCollection = $folder.files
        $file = Get-ChildItem "c:\CustomDefault.aspx"
        write-host "file is : " $file

        $fileCollection.Add("CustomeDefault.aspx", $file.OpenRead(), $true)   
        $site.Dispose() 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.