Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

I had problems like this with a site definition and variations. Basically what i think happens is that the SiteProvisioning.OnActivated event fires before the site in the schema has finished provisioning. So with my OnActivated i introduced a delay so that hopefully the site is fully provisioned when my edits start going on.

public partial class SiteProvisioning {
    public void OnActivated(SPFeatureReceiverProperties properties) {
        SPWeb web = null;
        SPSite site = null;
        if(properties.Feature.Parent is SPWeb) {
            web = (SPWeb)properties.Feature.Parent;
            site = web.Site;
        } else {
            site = (SPSite)properties.Feature.Parent;
            web = site.RootWeb;
        }
        Thread thread1 = new Thread(new ParameterizedThreadStart(UpdateNavigation));
        thread1.Start(new UpdateParameters(site.ID, web.ID));  
    }
    public class UpdateParameters {
        public Guid siteid;
        public Guid webid;
        public UpdateParameters(Guid siteid, Guid webid) {
            this.siteid = siteid;
            this.webid = webid;
        }
    }
    private void UpdateNavigation(object obj) {
        UpdateParameters paras = (UpdateParameters)obj; 
        Thread.Sleep(20000);
        using(SPSite site = new SPSite(paras.siteid)) {
            using(SPWeb web = site.OpenWeb(paras.webid)) {
                web.AllowUnsafeUpdates = true;

                //do some stuff
                web.AllowUnsafeUpdates = false;
                web.Update();
            }
        }
    }
}  
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.