0

I want to get author and editor on SP ListItem:

With this Page_load Code :

SPQuery myQuery = new SPQuery();
myQuery.Query = "<Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + id + "</Value></Eq></Where>";

SPListItemCollection myItemCol = list.GetItems(myQuery);


foreach (SPListItem item in myItemCol)
{
    author = item["Author"].ToString();
    editor = item["Editor"].ToString();
}

this.Controls.Add(new LiteralControl("<p>" + "Created by : " + author + "</p>"));
this.Controls.Add(new LiteralControl("<p>" + "Edited by: " + editor + "</p>"));

Result is :

enter image description here

When Another user edit an item : Created by must change. I want "Created by" to be a static data.

How to solve this problem?

  • 1
    Created by never changes for an specific item. – Juan Pablo Pussacq Laborde May 17 '16 at 12:15
  • Where i update a listItem created by must change :{ – Goshky May 17 '16 at 12:17
  • 1
    Why must change? – Juan Pablo Pussacq Laborde May 17 '16 at 12:20
  • Do you want to change the created by column using code in c#? as it will not change while updating the item information. Correct information from jpuddacq – Hardik May 17 '16 at 12:26
2

Author is the person who created the item. It is assigned once the item is created and never changed. Editor is changed every time item is modified.

Better use SPFieldUserValue to retrieve SPUser.

foreach (SPListItem item in myItemCol)
{
    SPFieldUserValue usrAuthor = new SPFieldUserValue(SPContext.Current.Web, item["Author"].ToString());
author = usrAuthor.User.Name;
    }
  • I'll try now.... – Goshky May 17 '16 at 13:20
  • thank you...What is 96;# ? how to remove this ? – Goshky May 17 '16 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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