更改“创建者"在 Sharepoint 2007 [英] Changing "Created By" in Sharepoint 2007

查看:39
本文介绍了更改“创建者"在 Sharepoint 2007的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd to allow the user to option to change the "created by" value when created an item in a sharepoint list. It seems that it's the default to hide this value and auto-populate the current user. I'd like to give the user this option when creating or modifying an item and pre-populate with the current user, but also give the user the option to change this field..

任何人有任何建议或谁能为我指明正确的方向?

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

非常感谢

推荐答案

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

编写一个 ItemEventReceiver 并覆盖 ItemUpdated 方法:

Write an ItemEventReceiver 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

        }
    });
}

更新代码;删除了迭代更新.

updated code; removed iterative update.

这篇关于更改“创建者"在 Sharepoint 2007的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆