views:

460

answers:

2

UPDATE

Worth noting that this is only happening when the site definition is called from SPWebApplication.Sites.Add, if I use the UI then this works fine. My code is impersonating the system account when calling this code.

Am I right in thinking that the ApplyWebTemplate() method of SPSite is asynchronous? If this is the case then my issue is probably one of timing. I.e. the required infrastructure is not yet in place when this code is run.

ORIGINAL QUESTION

I have a custom site definition which is using an SPProvisioningProvider to configure the site collection.

After calling ApplyWebTemplate("BLANKINTERNET#0") to apply the standard publishing portal site defintion, I am trying to create a new page based on the welcome page with TOC page layout.

However I am getting an exception when I call this piece of code

Dim pubSite As New PublishingSite(_siteColl)
Dim pubWeb As PublishingWeb = PublishingWeb.GetPublishingWeb(site)

Dim layouts() As PageLayout = Nothing
layouts = pubWeb.GetAvailablePageLayouts(_welcomeContentTypeID)

The following exception is raised at the GetAvailablePageLayouts method call.

Invalid field name. {7581e709-5d87-42e7-9fe6-698ef5e86dd3}

This is only happening on our live farm. It did not happen on dev or in the test environment so I am hoping it is a configuration change, but all references I can find on Tinterweb (sic) are related to the Field Type 'PublishingHidden' being missing, but how can I restore this given that this is happening in the site collection provisioning process?

Thanks

Charlie

A: 

are all required features (publishing infrastructure etc.) activated before performing this action? use something like the following:

// Check if the 'Publishing Prerequisites' feature is at the web and activated
var pubprereqguid = new Guid("A392DA98-270B-4e85-9769-04C0FDE267AA");
if (site.Features[pubprereqguid] == null)
{
  site.Features.Add(pubprereqguid);
}

// Check if the 'Publishing Resources' feature is at the web and activated
var pubresguid = new Guid("AEBC918D-B20F-4a11-A1DB-9ED84D79C87E");
if (site.Features[pubresguid] == null)
{
  site.Features.Add(pubresguid);
}
Colin
Because this site is based on the Publishing Portal definition these features should be activated. However, I guess I can use your code to ensure that this is the case before trying to implement code involving the publishing infrastructure. I'll see how this goes.
Charlie
Just tried this and both these features are activated on the relevant site collection before my code is run, but the error still occurs.
Charlie
A: 

You might want to check your code and make sure you are not accessing the field by its display name...

fieldName = web.lists[mylist].Fields["FieldName"].InternalName

UJ
I am not accessing any fields. As you can see from my code sample this is coming from code being run during GetAvailablePageLayouts(). I suspect the issue is one of timing.
Charlie