views:

438

answers:

4

Hi,

I'm trying to make a feature to upload a new publishing page in "Pages" library but it doesn't works the way I want. If I see the library using SharePoint Designer my publishing page appears, but it doesn't if I use Internet Explorer.

In the feature I configure the properties: ContentTypeId, ContentTye, Author, Title, FileRef, FileDirRef, FileLeafRef, FileType, LinkFilenameNoMenu, LinkFilename and DocIcon. In previous features, I faced the same problem and it was solved putting the ContentTypeId property. In this case, I don't know exactly where is the error.

A: 

I had a similar problem. It turned out i had to publish the uploaded file to make it visible.

Øyvind Skaar
+1  A: 

I use the following code to create a publishing page based on a page layout which is considered to be already provisioned and based on a content type. The code runs in the FeatureActivated event handler for your feature:

    using (SPWeb ParentWeb = properties.Feature.Parent as SPWeb)
    {
            PublishingWeb webpublish = PublishingWeb.GetPublishingWeb(ParentWeb);

            //retrieve the layout associated with our custom content type
            PageLayout[] layouts = webpublish.GetAvailablePageLayouts(new SPContentTypeId(MyContentTypeID));

            //first layout considered, as this is the one created by this feature
            PageLayout MyPageLayout = layouts[0];

            PublishingPageCollection PublishingPages = webpublish.GetPublishingPages();

            PublishingPage newPage = PublishingPages.Add("NewPublishingPageName.aspx", MyPageLayout);
            newPage.Title = "My first publishing page";

            newPage.ListItem.Update();

            //check-in and republish the page
            SPFile listItemFile = newPage.ListItem.File;

            //check that the file is not checked out - if it is,  check it in.
            if (listItemFile.CheckOutStatus != SPFile.SPCheckOutStatus.None)
            {
                listItemFile.CheckIn("Initial default content added.");
            }

            listItemFile.Publish("");
            listItemFile.Approve("");                
    }
Tudor Olariu
A: 

I have similar solution as Tudor, I´ll publish that code to just in case:

...get SiteCollection (SPSite)...

PublishingSite pSite = new PublishingSite(site);
PageLayout layout = pSite.PageLayouts["MyLayout"];

PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(site);

if(pWeb.GetPublishingPages()[pWeb.PagesList.Title + "/" + "MyPage.aspx"] == null)
{
  PublishingPage page = pWeb.GetPublishingPages().Add("MyPage.aspx", layout);
  page.Title = "MyTitle";
  page.Update();
  page.CheckIn("Added MyPage.aspx");
}
Johan Leino