【发布时间】:2012-01-28 04:01:59
【问题描述】:
我会允许用户在共享点列表中创建项目时选择更改“创建者”值。似乎默认隐藏此值并自动填充当前用户。我想在创建或修改项目并使用当前用户预填充时为用户提供此选项,但也为用户提供更改此字段的选项..
任何人有任何建议或谁能指出我正确的方向?
非常感谢
【问题讨论】:
标签: sharepoint
我会允许用户在共享点列表中创建项目时选择更改“创建者”值。似乎默认隐藏此值并自动填充当前用户。我想在创建或修改项目并使用当前用户预填充时为用户提供此选项,但也为用户提供更改此字段的选项..
任何人有任何建议或谁能指出我正确的方向?
非常感谢
【问题讨论】:
标签: sharepoint
“创建者”列的internal name 是作者。
编写一个 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
}
});
}
编辑:更新代码;删除了迭代更新。
【讨论】:
strUserId 变量。您可以使用 SPUser 对象直接设置用户字段。所以你可以使用spListItem["Author"] = spUser;
谢谢,伙计们,但我应该提到我没有为此使用任何代码。
我的解决方案是将 Created By 字段重命名为 Created By (unused),创建一个新的 Created By 字段并使用一些自定义Javascript 在页面加载时填充字段。
【讨论】: