Has anyone at all look at uploading a file to/using an existing SPFile in the PublishingPageCollection.Add() method?

I'm referring to this override specifically: http://msdn.microsoft.com/en-us/library/ms495757.aspx

The docs just say "File to convert to get the Page content" - how does it convert it? Does it take an existing Publishing Page just full of the mso: meta tags filled with content and bung it into the specified layout or?

But James, Why!?

Got a requirement where I'd like to be able to very quickly knock up a site structure, including sticking in some pre-created Publishing Pages into the site as test data (saves me creating lots of "testarticles").


This would be using the Document Conversion Service, wouldn't it? I can't imagine why you'd want to convert an existing Publishing Page to ... a Publishing Page. It think that overload might be for Document conversion.

I would suggest uploading to a document library and then invoking the Document Conversion service.

I have added a page programmatically - but not converting anything:

string fileName = "Somefile.aspx";
string contentTypeString = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2";
string pageLayoutName = "HomeLayout.aspx";
string newPageTitle = "Some Title";

PublishingWeb elevPubWeb = PublishingWeb.GetPublishingWeb(elevWeb);

SPContentTypeId cTypeId = new SPContentTypeId(contentTypeString);

PageLayout[] layouts = elevPubWeb.GetAvailablePageLayouts(cTypeId);
PageLayout layout = layouts[1];
foreach (PageLayout p in layouts)
    if (p.Name == pageLayoutName)
        layout = p;
    PublishingPageCollection ppc = elevPubWeb.GetPublishingPages();
    PublishingPage newPage = ppc.Add(fileName, layout);
    newPage.Title = newPageTitle;
catch (Exception ex) 
//Handle page layout not found
  • Good point - should probably have clarified, I'll update my question. – James Love Feb 14 '11 at 17:06
  • Well, if it's just 'Lorem Ipsum' type stuff, I'd think about just creating the pages directly - as posted above - rather than using documents and converting. Obviously, if you want actual content, that gets harder. – Andy Burns Feb 15 '11 at 10:58

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.