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're on the right track! The issue is that you're directly using the
clientIdto set the "Author" and "Editor" fields. SharePoint expects user objects, not just IDs, for these fields.Here's how to modify your code to display a custom name:
1. Retrieve User Information:
Instead of directly using
clientId, fetch the user object associated with theclientId. You can use thecontext.Web.GetUserById(clientId)method for this.2. Set Display Name:
Once you have the user object, access its property (which usually represents the display name) and use it to set the "Author" and "Editor" fields.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.