2

I'm trying to deploy a web template to Sharepoint 2013 as a sandboxed solution with Visual Studio. I was hoping that I could "replace" the default.aspx with my own page. The deployment consists of two features.

First Feature: The web template with onet.xml and Elements.xml

Second Feature: A module containing a custom .aspx file (my page)

What I'm trying to achieve is:

After creating a new site collection with the web template as a template my custom .aspx file should be displayed on the Home link. Normally the default.aspx page ist loaded. I thought I could display my custom page by default but it doesn't work. (Server Error in '/' Application.)

My onet.xml looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<Project Revision="11" Title="$Resources:spscore,PortalTitle;">
  <NavBars/>
  <ListTemplates/>
  <DocumentTemplates/>
  <Configurations>
    <Configuration ID="0" Name="Default">
      <Modules>
        <Module Name="Default" />
      </Modules>
      <SiteFeatures>
        <Feature ID="9257055b-ce3b-4839-9be8-1e0bba869ba1" />
      </SiteFeatures>
      <WebFeatures>
      </WebFeatures>
    </Configuration>
  </Configurations>
  <Modules>
    <Module Name="Default" Url="" Path="">
      <File Url="MyPageModule/defaultya.aspx" NavBarHome="True"></File>
      <!--<File Url="default.aspx" NavBarHome="True"></File>-->
    </Module>
  </Modules>
</Project>

The feature ID references the second feature.

This is the elements.xml from my custom page:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="MyPageModule">
    <File Path="MyPageModule\defaultya.aspx" Url="MyPageModule/defaultya.aspx">
      <Property Name="Title" Value="MyTitle" />
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
    </File>
  </Module>
</Elements>

This is the elements.xml from the web template:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <WebTemplate
    Name="MinimalWebTemplate01"
    Title="MinimalWebTemplate01"
    BaseTemplateID="1"
    BaseConfigurationID="0"
    BaseTemplateName="STS"
    xmlns="http://schemas.microsoft.com/sharepoint/" />
</Elements>

Maybe its just my understanding that needs to be straightend. I thought this would be a nice solution to replace the default.aspx with my own, rather than renaming it through a feature receiver.

EDIT:

Following Derek's suggestion I changed my elements.xml of the module provided by adding the suggested propertybag:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="MyPageModule">
    <File Path="MyPageModule\defaultya.aspx" Url="SitePages/defaultya.aspx">
      <Property Name="Title" Value="MeinPageLayoutPropTitle" />
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
    </File>
  </Module>
  <PropertyBag Url="" ParentType="Folder" RootWebOnly="false" AlwaysCreateFolder="true">
    <Property Name="vti_welcomePage" Type="string" Value="SitePages/defaultya.aspx"></Property>
  </PropertyBag>
</Elements>

But it seems to have no impact on the home page of the created site. I also changed the onet.xml by removing the Default-Module. For now it looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<Project Revision="11" Title="$Resources:spscore,PortalTitle;">
  <NavBars/>
  <ListTemplates/>
  <DocumentTemplates/>
  <Configurations>
    <Configuration ID="0" Name="Default">
      <Modules>
        <!--<Module Name="Default" />-->
      </Modules>
      <SiteFeatures>
        <Feature ID="9257055b-ce3b-4839-9be8-1e0bba869ba1" />
      </SiteFeatures>
      <WebFeatures>
      </WebFeatures>
    </Configuration>
  </Configurations>
  <Modules>
    <!-- Module is deployed through feature, which shouldn't be done twice -->
    <!-- <Module Name="Default" Url="" Path="">
      <File Url="/MyPageModule/defaultya.aspx" NavBarHome="True"></File>
      <File Url="default.aspx" NavBarHome="True"></File>
    </Module>-->
  </Modules>
</Project>

If I call http://myserver.com/sites/testsite SharePoint tries to load the default.aspx which is no longer provided. The screen I get looks like this:

enter image description here

However if I'm calling http://myserver.com/sites/testsite/SitePages/defaultya.aspx I can see my custom page.

One more note: I'm deploying both features at site level.

1

I'm not sure there's enough information here to solve your issue, but here's a couple thoughts after seeing your code:

  • Your are deploying your custom page twice, once via the onet and once via the second feature. You only need one, and either will do.
  • What page are you on when you see the server error? Is it your custom page? If so there's an issue with your page. Does the rest of the site provision properly? If you're not sure go to _layouts/viewlsts.aspx and check that all your stuff is there.
  • You have not changed the deployment url of your page. What you've done will work, but generally you'll want to deploy to a document library like SitePages.
  • You need some code to set your custom page as the site's real home page. You do this through a web property called vti_welcomepage, like this:

    enter image description here

  • Sorry to post code in a screen shot, but my XML kept getting stripped out, and I couldn't seem to figure out how to make it render. – Derek Gusoff Jun 14 '14 at 1:49
  • You can add it to your post, mark it and then click the "Two brackets-icon" above the input field. Make sure to leave a blank line before the code as well :) – Robert Lindgren Jun 14 '14 at 9:21
  • Hey Derek, I appreciate your detailed answer. I followed your suggestions but I still cannot see my custom page as the Homepage. Can you please check my Edits in the question? Thanks so far, I hope I'm able to give back something to the community regarding Sharepoint when I've gained more experience. :) – user29651 Jun 16 '14 at 8:06
  • can you navigate directly to the custom home page? If so, what do you see? If the page is not set as the default home page then possibly the web property didn't take. Easiest way to check this is, if you have server access, use SharePoint Manager. You can also get them via SharePoint designer. – Derek Gusoff Jun 16 '14 at 11:54
  • Hi Derek, as I mentioned, I can navigate to my custom page and see it. The only problem left is that I guess "the web property didn't take". There is no default.aspx in the site collection, but my custom page is stored at /SitePages/defaultya.aspx as expected. Still: Why doesn't it get set as the homepage? – user29651 Jun 16 '14 at 12:09

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.