In Sharepoint you can provision publishing pages via Module element using the following xml:
1: <Module Name="Pages" Url="$Resources:cmscore,List_Pages_UrlName;">
2: <File Url="default.aspx" Type="GhostableInLibrary" Level="Draft">
3: ...
4: </File>
5: </Module>
However with this approach default.aspx page will be provisioned with draft version (0.1). It means that it will not visible for anonymous users if you use FBA in your web application. You need to go and publish it manually. It is not easy if you have large project with many publishing pages. Another solution – publish pages via object model. But it requires some additional programming. The desirable solution is to specify Level=”Published” instead of Level=”Draft” in xml without any additional steps.
Take a look at xml above. Level attribute of File tag is mapped on SPFileLevel enum defined in Microsoft.SharePoint.dll:
1: public enum SPFileLevel : byte
2: {
3: Checkout = 0xff,
4: Draft = 2,
5: Published = 1
6: }
So lets try to specify Published in Level attribute:
1: <Module Name="Pages" Url="$Resources:cmscore,List_Pages_UrlName;">
2: <File Url="default.aspx" Type="GhostableInLibrary" Level="Published">
3: ...
4: </File>
5: </Module>
Unfortunately it will fail with the following error when you will try to add solution with this feature into solution store:
Feature definition with Id … failed validation, file '…\elementManifest.xml': The 'Level' attribute is invalid - The value 'Published' is invalid according to its datatype 'http://schemas.microsoft.com/sharepoint/:FileLevelType' - The Enumeration constraint failed. The Solution installation failed.
In order to fix this error you should change wss.xsd file stored i n"12\TEMPLATE\XML". Find the following section:
1: <xs:simpleType name="FileLevelType">
2: <xs:restriction base="xs:string">
3: <xs:enumeration value="Draft" />
4: </xs:restriction>
5: </xs:simpleType>
and add <xs:enumeration value="Published" /> element after <xs:enumeration value="Draft" /> so the final result will be:
1: <xs:simpleType name="FileLevelType">
2: <xs:restriction base="xs:string">
3: <xs:enumeration value="Draft" />
4: <xs:enumeration value="Published" />
5: </xs:restriction>
6: </xs:simpleType>
After that you will be able to publish pages during provisioning, i.e. pages will be provisioned with published status (version 1.0).
I tried setting this in my environment and I stopped getting the error in Visual Studio but the item is still showing up as 'Draft' when it gets deployed to my SharePoint site.
ReplyDeleteThanks, James
James,
ReplyDeletecheck version history of your pages. Is it less or greater than 1? If it is > 1, then probably some feature receiver adds web parts on page after it was published and didn't published it
Or you could just leave the Level arrtibute out entirely and the file will automatically be provisioned in a published state.
ReplyDeleteModifying OOTB files in TEMPLATE/XML will leave your SP installation in an unsupported state.
leedale,
ReplyDeletethanks for comment, but when we tried to leave files without Level attribute they were provisioned in Draft state in our case. And yes - any modification of the OTB files should be avoided. However I don't think this modification will affect smth. I would rather consider absence of the Published choice in xsd file as a bug.
This is fixed in 2013 version. now in the xsd you can see the "Published"as well.
ReplyDeletethanks for update
ReplyDelete