SharePoint - Invalid Field Name Error

UPDATE

It's worth noting that this only happens when the site definition is called from SPWebApplication.Sites.Add, if I'm using the UI then it works fine. My code impersonates the system account when calling this code.

Did I understand correctly that SPSite's ApplyWebTemplate () method is asynchronous? If so, then my problem is probably one of the timing. That is, the required infrastructure is not yet installed when this code is run.

ORIGINAL QUESTION

I have a custom site definition that uses the SPProvisioningProvider to configure a site collection.

After calling ApplyWebTemplate ("BLANKINTERNET # 0") to apply the standard publishing portal site validation, I am trying to create a new page based on the welcome page with a 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 thrown when the GetAvailablePageLayouts method is called.

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

This only happens on our farm. This did not happen on dev or in a test environment, so I hope this is a configuration change, but all the links I can find on Tinterweb (sic) are related to the lack of a "PublishingHidden" field type, but how can I recover this given what happens during the creation of a site collection?

thank

Charlie

0


source to share


2 answers


are all required features (publishing infrastructure, etc.) activated before doing this? 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);
}

      

0


source


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

0


source







All Articles