0

I am copying over items from one list to another list.

After copying the "Author" field gets populated with "System Account" and so I wish to update some fields in the destination list as follows.

I have a list with a custom Person column named "OriginalAuthor".

I want to replace the value of built-in "Author" with the value of "OriginalAuthor".

I also wish to achieve the same with the modified field (which currently DOES work)

I found a few examples on-line but could not get any to work. So far I have the following:

foreach (SPListItem destItem in destList.Items)
{
     SPFieldUserValue val = new SPFieldUserValue(web.Site.RootWeb, destItem["OriginalAuthor"].ToString());

     destItem["Author"] = val;
     destItem["Modified"] = destItem["OriginalModified"];
     destItem.Update();
}
destList.Update();

The modified date gets replaced however, the Author field remains the same.

How can I get this to work?

thanks, KS

3
  • destItem["Author"] = destItem["OriginalAuthor"], this doesn't work? if OriginalAuthor is Person field too, it should! Oct 24, 2012 at 20:23
  • Yes, that's what I thought - but it just doesnt work.
    – Perplexed
    Oct 24, 2012 at 20:28
  • Perplexed, have a look at this URL, do read at the end of the post - where it says it will not update created by field but posted a workaround by a friend! Oct 24, 2012 at 21:11

3 Answers 3

0

Is there a reason you can't grab the Author field from the original item?

My other thought has to do with using SPListItem.SystemUpdate() instead of Update(), but that has more to do with not changing Modified/Modified By than Author.

1
  • Yes, I tried that, but as suspected it stopped me from updating the modified date and it didnt affect the Author field either.
    – Perplexed
    Oct 24, 2012 at 20:34
0

I'm not sure and I cannot test it right now, but i think author field is a person field, so you cannot just put a name there, i think it should be an spuser or maybe some other type which references to user in SP.

Or you can also try this code:

SPList list = web.Lists["myList"];
list.Fields["Author"].ReadOnlyField = false;
SPListItem item = list.Items.Add();
item["Author"] = "value";
item.SystemUpdate(false);
list.Fields["Author"].ReadOnlyField = true;

Happy coding

0

Well after being unable to accomplish this I have decided to use Sharepoint Content Manager to copy the items which preserves the required fields. Thanks to all for your assistance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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