Hi @ASR ,
Per my test, We can get file author by CSOM. Please refer to following code
List targetList = clientcontext.Web.Lists.GetByTitle("Documents");
ListItem oItem = targetList.GetItemById(2);
CamlQuery oQuery = new CamlQuery();
oQuery.ViewXml = @"<View><Query><Where>
<Eq>
<FieldRef Name='LinkFilename' />
<Value Type='Text'>Document.docx</Value>
</Eq>
</Where></Query></View>";
ListItemCollection oItems = targetList.GetItems(oQuery);
clientcontext.Load(oItems);
clientcontext.ExecuteQuery();
oItem = oItems.FirstOrDefault();
File targetFile = oItem.File;
clientcontext.Load(targetFile);
User oUser = targetFile.Author;
clientcontext.Load(oUser);
clientcontext.ExecuteQuery();
Console.WriteLine("Author: " + oUser.LoginName);
If we need list owner. We need to use SPList.Author property returns the SPUser field.
using(SPSite site = newSPSite(strURL))
{
using(SPWeb web = site.OpenWeb())
{
SPList list = web.Lists.TryGetList(listName);
if (list != null) {
SPUser listAuthor = list.Author;
string authorName = listAuthor.Name;
Console.WriteLine("List Author Name: {0}", authorName);
retry = false;
} else
{
Console.WriteLine("List with the name \"{0}\" not exists Please try some other name.", listName);
retry = true;
}
}
}
---------update---------
We can get author.Title but it seems there is no UserPrincipalName property in SharePoint 2019. Here is the sample for reference
Web web = clientContext.Web;
List list = web.Lists.GetByTitle("TestList");
clientContext.Load(list, l => l.SchemaXml);
clientContext.ExecuteQuery();
string schemaxml = list.SchemaXml;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(schemaxml);
XmlNode listElement = xmlDoc.GetElementsByTagName("List")[0];
string authorid = listElement.Attributes["Author"].Value;
User author = web.GetUserById(Convert.ToInt32(authorid));
clientContext.Load(author);
clientContext.ExecuteQuery();
Console.WriteLine(author.Title);
Console.ReadLine();
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.