Skip to content

Update an item without loading it first #1140

Answered by m-urubek
m-urubek asked this question in Q&A
Discussion options

You must be logged in to vote

I have figured it out. Following method works. Took me a few hours of going through source code.

public static void Update(PnPContext context, string listName, int itemId) {
        Type? listItemType = Type.GetType("PnP.Core.Model.SharePoint.ListItem, PnP.Core");
        IListItem listItemInstance = (IListItem)listItemType.GetConstructors().FirstOrDefault().Invoke(null);

        PropertyInfo? idProperty = listItemType.GetProperties().Where(pr => pr.Name == "Id").FirstOrDefault();
        idProperty.SetValue(listItemInstance, itemId);

        listItemInstance.Values.Add("Title", "test1");

        IList list = context.Web.Lists.GetByTitle(listName);
        listItemInstance.Parent = lis…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jansenbe
Comment options

Answer selected by jansenbe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants