Change "Created" in Sharepoint 2007

I would allow the user to change the value of "created by" when creating the item in the sharepoint list. This seems to be the default to hide this value and automatically populate the current user. I would like to give the user this opportunity when creating or modifying an element and pre-populate the current user, but also give the user the opportunity to change this field.

Anyone have suggestions or who can point me in the right direction?

Many thanks

+3
source share
2 answers

The internal column name for the Created column is the author.

Write an ItemEventReceiver element and override the ItemUpdated method:

//USER_NAME is user account name that you want to set.

public override void ItemUpdated(SPItemEventProperties properties) { 
    SPSecurity.RunWithElevatedPrivileges(delegate   
    {     
        using (SPWeb web = properties.OpenWeb())     
        {
            web.AllowUnsafeUpdates = true;

            // Insert any other updates here

            SPUser spUser = web.EnsureUser("USER_NAME");
            string strUserId = spUser.ID + ";#" + spUser.Name;
            spListItem["Author"] = strUserId;
            spListItem.Update();

            // if you do not want to change the Modified or Modified By fields,
            // use spListItem.SystemUpdate() instead

        }
    });
}

EDIT: ; .

+8

, , , .

, "" ( ), "" - Javascript .

-1

All Articles