1

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)
        {
            pageFile.CheckOut(SPFile.SPCheckOutType.Offline,DateTime.Today.ToString());
        }
        manager.WebParts[i].AuthorizationFilter = ";;;;User Group";
        manager.SaveChanges(manager.WebParts[i]);

        if (pageFile.Item.ParentList.ForceCheckout == true && pageFile.CheckOutType != SPFile.SPCheckOutType.None)
        {
            pageFile.CheckIn("Published");
        }
        web.AllowUnsafeUpdates = false;
        break;
    }
}

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.