I have been hitting my head against a wall lately with a custom master page and some custom sites. There appears to be an incompatibility between the 2. Since they come from separate sources, finding out where to point the finger is a little tricky. My custom master page makes use of Publishing, Feature Stapling, among other things.
The behaviour is that when I edit a community page and then click publish, it would throw an exception
System.ArgumentException: Invalid SPListItem. The SPListItem provided is not compatible with a Publishing Page.
at Microsoft.SharePoint.Publishing.PublishingPage.GetPublishingPage(SPListItem sourceListItem)
at Microsoft.SharePoint.Publishing.Internal.WebControls.PublishingPagePublishHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
I have yet to figure out what is going on here. However here are some other observations
$web = Get-SPWeb <SPWeb URL>
[Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)
This returns false despite the Publishing tab being there and the SharePoint Server Publishing site feature is activated.
So, ignoring the False, I continue with this:
$publishingweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$publishingpages = $publishingweb.GetPublishingPages()
This throws an exception:
Exception calling "GetPublishingPages" with "0" argument(s): "The site is not valid. The 'Pages' document library is missing."
At line:1 char:53
+ $publishingpages = $publishingweb.GetPublishingPages <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
... but the Pages document library does indeed exist and I do have administrative rights on it.
I also try the following:
$pages = $web.Lists | Where-Object {$_.Title -eq "Pages"}
$page = $pages.Items | Where-Object {$_.Name -eq "default.aspx"}
[Microsoft.SharePoint.Publishing.PublishingPage]::IsPublishingPage($page)
... and get False which I would expect given the results from above. What doesn’t make sense is that this default.aspx page does have a Publish tab on it.
I then decided to try the IsPublishingWeb again, but without the custom master page. This is still giving me False. So, I guess I will start pointing the finger towards my custom site ...
Any news on this issue yet?
ReplyDeleteTry this
ReplyDelete$web = get-spweb http://site-collection/path-to-affected-site
$correctId = $web.Lists["Pages"].ID
$web.AllProperties["__PagesListId"] = $correctId.ToString()
$web.Update()
$web.AllProperties["__PublishingFeatureActivated"] = "True"
$web.Update()
You mad my day Debjit.. Thanks I am searching for this for so many times
DeleteVery nice na?
DeleteMany thanks from me as well! Just helped me solve the same issue
DeleteThis worked a treat, added it to a powershell script that was auto creating sites from templates :)
DeleteSi (uk)
Thanks a lot, Debjit! Spent a day on this until I found your post.
ReplyDeleteDebjit thanks this also solved my problem instantly. I've been struggling with about 30 sites experiencing the same issue.
ReplyDeleteDebjit, I too appreciate your contribution, it solved my problem.
ReplyDeleteWhen running $web.AllProperties["__PagesListId"] = $correctId.ToString()
ReplyDeleteI receive an error "You cannot call a method on a null-valued expression"
Any ideas?
What are the values of $web and $correctId?
DeleteHello. Great Post! this solution worked on one of the sites but not working on another:( After calling first $web.Update() I get following error:
ReplyDeleteException calling "Update" with "0" argument(s): "Item has already been added.
Key in dictionary: 'H?↑' Key being added: 'H?↑'"
At line:1 char:12
+ $web.Update <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Any ideas?
It's been a long time since I looked at this. Off the top of my head, perhaps your $web object is stale? Maybe try getting it again with $web = Get-SPWeb $web.Url and do the second update?
Delete