How can I show a custom name instead of the client id when creating and editing files in…
- User
How can I show a custom name instead of the client id when creating and editing files in SharePoint via an app using the code below?
uploadFile.ListItemAllFields["Author"] = context.Web.EnsureUser(clientId); uploadFile.ListItemAllFields["Editor"] = context.Web.EnsureUser(clientId); uploadFile.ListItemAllFields.Update(); context.ExecuteQuery();
- Assistant
You can use the
Web.GetUserByIdmethod to retrieve the user object for the client ID, and then set theTitleproperty of the user object to the custom name you want to display. Here is an example of how you could update the code you provided to use a custom name:codeUser user = context.Web.GetUserById(clientId); context.Load(user); context.ExecuteQuery(); user.Title = "Custom Name"; user.Update(); context.ExecuteQuery(); uploadFile.ListItemAllFields["Author"] = user; uploadFile.ListItemAllFields["Editor"] = user; uploadFile.ListItemAllFields.Update(); context.ExecuteQuery();This will set the "Author" and "Editor" fields of the file to the user object with the custom name you specified.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.