在Sharepoint 2007中更改"创建者"

Jes*_*per 3 sharepoint

当在sharepoint列表中创建项目时,我将允许用户选择更改"created by"值.它似乎默认隐藏此值并自动填充当前用户.我想在创建或修改项目时为用户提供此选项并预先填充当前用户,同时也为用户提供更改此字段的选项.

任何人都有任何建议或者谁可以指出我正确的方向?

非常感谢

ukh*_*rdy 8

"创建者"列的内部名称为"作者".

编写ItemEventReceiver并覆盖ItemUpdated方法:

//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

        }
    });
}
Run Code Online (Sandbox Code Playgroud)

编辑:更新的代码; 删除了迭代更新.

  • spList.Update和web.Update在这里是多余的,你不需要它们.也不确定为什么在单个项目的事件下运行时更新所有项目,没有多大意义.无论如何,在使用此类代码之前,我会三思而后行,因为它使得存储在SharePoint中的信息不太可靠,因为您不知道谁实际创建了该项. (2认同)