I need to update the sp page content by using C# code.

I have used below code to check out and update and check in.

SPLimitedWebPartManager manager = pageFile.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
for (int i = 0; i < manager.WebParts.Count; i++)
    if (manager.WebParts[i].Title == "PageTitle")
        web.AllowUnsafeUpdates = true;
        if (pageFile.Item.ParentList.ForceCheckout == true && pageFile.CheckOutType == SPFile.SPCheckOutType.None)
        manager.WebParts[i].AuthorizationFilter = ";;;;User Group";

        if (pageFile.Item.ParentList.ForceCheckout == true && pageFile.CheckOutType != SPFile.SPCheckOutType.None)
        web.AllowUnsafeUpdates = false;

But it shows below error while executing manager.SaveChanges(manager.WebParts[i]);

The file is not checked out. You must first check out this document before making changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.