Monday, February 14, 2011

Unable to Insatiate Module – SharePoint Error

Have you ever come across such error?  I faced.. and solved
This error is basically related to the module element and usually comes when you try to provision a file to the SharePoint site which never exists on physical path / file system of the server
Here is the example case:
I am trying to provision a page named stylish.aspx to pages library same as default.aspx in onet.xml

<Module Name="SampleModule" Url="$Resources:cmscore,List_Pages_UrlName;" Path="">

<File Url="Default.aspx" NavBarHome="false" Type="GhostableInLibrary">
  <Property Name="Title" Value="My Default Page" />
  <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx, ~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx;" />
  <Property Name="ContentType" Value="$Resources:cmscore,contenttype_page_name;" />
</File>
     
<File Url="Stylish.aspx" NavBarHome="false" Type="GhostableInLibrary">
<Property Name="Title" Value="My Stylish Page" />
<Property Name="PublishingPageLayout"
Value="~SiteCollection/_catalogs/masterpage/ MyPageLayout.aspx, ~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx" />
<Property Name="ContentType" Value="$Resources:cmscore,contenttype_page_name;" />
</File>
</Module>

If you try above case then you will get this error, unable to insatiate module ……
Well what’s the problem?
Yes , I was trying to add page named Stylish.aspx with virtual url Stylish.aspx which never exist
If you open any site template directory under [14]\Layouts\Template\SiteTemplate then you will find default.aspx and that’s the reason why SharePoint needs that
SharePoint searches file named default.aspx on file system and then provisions file to SharePoint site


Solution:
So above error can be solved like using a Name attribute of File Element

<Module Name="SampleModule" Url="$Resources:cmscore,List_Pages_UrlName;" Path="">

<File Url="Default.aspx" NavBarHome="false" Type="GhostableInLibrary">
  <Property Name="Title" Value="My Default Page" />
  <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx, ~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx;" />
  <Property Name="ContentType" Value="$Resources:cmscore,contenttype_page_name;" />
</File>
     
<File Name="Stylish.aspx" Url="Default.aspx" NavBarHome="false" Type="GhostableInLibrary">
<Property Name="Title" Value="My Stylish Page" />
<Property Name="PublishingPageLayout"
Value="~SiteCollection/_catalogs/masterpage/ MyPageLayout.aspx, ~SiteCollection/_catalogs/masterpage/MyPageLayout.aspx" />
<Property Name="ContentType" Value="$Resources:cmscore,contenttype_page_name;" />
</File>
</Module>

No comments:

Post a Comment