I'm trying to activate "
SharePoint Publishing Server Infrastructure" and "
SharePoint Server Publishing" by C# code. Here's my code:
SPSite siteCollection = new SPSite("http://MySitecollectionUrl"); SPWeb rootweb = siteCollection.RootWeb; Guid guid1 = new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa"); Guid guid2 = new Guid("94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb"); siteCollection.Features.Add(guid1, true); rootweb.Features.Add(guid2, true);
After running the code, I met this error:
Error Microsoft.SharePoint.SPFeatureDependencyNotActivatedException: Dependency feature 'PublishingSite' (id: f6924d36-2fa8-4f0b-b16d-06b7250180fa) for feature 'PublishingWeb' (id: 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb) is not activated at this scope
But when I check my Sharepoint site, the "Sharepoint Publishing Server Infrastructure" feature was activated by my code.
So, what am I doing wrong here?
I've tried activating the "
SharePoint Publishing Server Infrastructure" by code, and then activated the "
SharePoint Server Publishing" manually, and everything works OK.
This issue really makes me confused. I really don't know why, are there any diffrences between activating feature by code and manually ?