1

I want to Update the Author field of Folder property/item property. I have seen many posts online, I tried different link but I didn't get the Success. I followed This Link. I didn't get any error while Updating the item. But the values of Author field has not been updated in Document Library?

FYI - I have created a Console Application and working with SharePoint 2016. I don't have option to use the Server side object model. I want to Update it with the CSOM only.

The same way I can update the Editor field.

0

Try change:

  • item.Update(); //Apply the change to item.SystemUpdate(); //Apply the change

or try this code (tested and a little edited):

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            {
                UpdateListItem();
            }

        }
        public static void UpdateListItem()
        {
            var siteURL = "https://sharepoint16.dev.cz/tweb";
            var listName = "Set";
            var listItemId = 1;
            var createdBy = "nespor@dev.cz";
            var modifiedBy = "nespor@dev.cz";

            ClientContext context = new ClientContext(siteURL);
            List list = context.Web.Lists.GetByTitle(listName);
            ListItem item = list.GetItemById(listItemId);
            FieldUserValue author = GetUsers(context, createdBy);
            FieldUserValue editor = GetUsers(context, modifiedBy);
            item["Author"] = author;
            item["Editor"] = editor;
            item.Update();
            context.ExecuteQuery();
        }

        //get user by username
        public static FieldUserValue GetUsers(ClientContext clientContext, string UserName)

        {
            FieldUserValue userValue = new FieldUserValue();
            User newUser = clientContext.Web.EnsureUser(UserName);
            clientContext.Load(newUser);
            clientContext.ExecuteQuery();
            userValue.LookupId = newUser.Id;
            return userValue;
        }
    }
}

Before: enter image description here

After: enter image description here

If its not working for you, make sure you have appropriate permissions (Site Collection Administrator or Site Admin) and you are set createdBy and modifiedBy variables with correct login name.

  • No. this is also not working for Author field. And SystemUpdate() is not working, because I'm working in SharePoint 2016. – Krunal Patel Feb 1 at 3:24
  • I edited the answer, test the code, it's working for me, so make sure you have appropriate permissions and set correct login name. – Zdeněk Vinduška Feb 1 at 8:11
0

I got it working by Update Author and Editor both the fields together. Firstly I was just updating the Author field that was not working.

So to update the Author field, you must need to Update the Editor field as well, otherwise it will not work.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.