SharePoint/WSS:修改“創建者”字段? (SharePoint/WSS: Modify "created by" field?)


問題描述

SharePoint/WSS:修改“創建者”字段? (SharePoint/WSS: Modify "created by" field?)

All ‑ 

I am using WSS 3.0. Currently, HR will upload an employee's internal company resume to a document library on our site, but for privacy reasons, we must then restrict access to that document library, which forces users to then go through HR each time they want to update their resume.

My thought is to create a list with attachments enabled that allows users to only view/edit their own items, and then give HR permission to manage all entries. This works with the exception that HR will need to create the initial list item and attach the resume, which means the list item will be "created by {hr}" and not visible/editable by the end user whose resume is attached. 

Any ideas on how I can either allow HR to modify the "created by" field on upload so end users will see and can edit their resume, or go about this in a different way?

Thanks!

‑‑‑‑‑

參考解法

方法 1:

Create a document library to hold the resume's. Then give the HR department (SharePoint User group) "read / write all" permissions on the library, the give everyone else read / write your own" rights. Create a Content Type called "Resume" based on the out‑of‑the‑box Document content type. Then add a field that contains the Employee (SPUser field) whom the resume concerns to the content type (and any other fields required, i.e. name, address etc.). Have HR fill this in correctly when creating the listitem (make the fields required).

Then,  write a itemeventreceiver bound to the content type you just created and override the ItemUpdated event. 

The code would be something like the following:

public override void ItemUpdated(SPItemEventProperties properties)
{
  SPSecurity.RunWithElevatedPrivileges(delegate
  {
    using (SPWeb web = properties.OpenWeb())
    {
       web.AllowUnsafeUpdates = true; 
       var item = web.Lists[properties.ListId].GetItemById(properties.ListItemId);
       if (item != null)
       {
         if (item.Fields.ContainsField("Employee"))
         {
           item["Author"] = item["Employee"]; 
           // Author is the internal name of the Created by field, 
           // always use Internal Names!
           DisableEventFiring();
           item.SystemUpdate();
           EnableEventFiring();
         }
       }
     }
   });
}

you can bind the ItemEventReceiver using a FeatureReceiver to the content type like so:

SPContentType docCt = web.ContentTypes[new SPContentTypeId("CONTENTYPE ID GOES HERE")];
docCt.EventReceivers.Add(SPEventReceiverType.ItemUpdated, "ASSEMBLYNAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=TOKEN", "FULLY QUALIFIED CLASSNAME");
docCt.Update();

方法 2:

Why not just use a document library for the resumes? (instead of a list w/ attachments.)  You can give HR full read/write to all documents within, and the owner of the resume will have contribute permissions to only their own resume.

方法 3:

I found a way to change the Created By field using SharePoint Designer to create a workflow.

  1. Create a dummy field in your list with an easy‑to‑spot name, e.g. XYZZY. Make it a "person or group" field.
  2. In SharePoint Designer, create a Workflow for your list. Allow manual start and start automatically when new item is created.
  3. Actions ‑> Set Field in Current Item ‑> Set XYZZY to the field in your list that contains the user account you want to put into Created By.
  4. Click Finish
  5. Now, open your workflow .xoml file with Notepad. Replace "XYZZY" with "Author". Save the .xoml file.
  6. Open the workflow in Designer. Click Finish so that it reprocesses with the new code.
  7. Delete the dummy field from the list.
  8. Run the workflow on each existing item in your list. New items will self‑correct automatically.

方法 4:

With a custom upload screen you could change the context of the current user before doing the upload.  It requires looking up the user token using something like the following (these are snippets of working code with error handling and other stuff removed).  Note that EnsureUser will require that the current user basically be an admin/owner.

using (SPSite site = GetImpersonatedSite(runAsUser))
{
    using (SPWeb web = site.OpenWeb())
    {
        // Do stuff here
    }
}

private SPSite GetImpersonatedSite(string username)
{
    user = SPContext.Current.Web.EnsureUser(username);
    SPSite site = new SPSite(SPContext.Current.Web.Url, user.UserToken);
    return site;
}

(by MarkColinJason WattsFrancoiseKirk Liemohn)

參考文件

  1. SharePoint/WSS: Modify "created by" field? (CC BY‑SA 3.0/4.0)

#permissions #wss #sharepoint






相關問題

SharePoint/WSS:修改“創建者”字段? (SharePoint/WSS: Modify "created by" field?)

從 MS Access 訪問 .mdb 文件中的後端表 (Accessing backend tables in .mdb files from MS Access)

如何以編程方式對 AD OU 條目設置“列出內容”和“列出對象”權限? (How can I programmatically set "List Content" and "List Object" permissions on AD OU entries?)

嘗試使用 C# 設置註冊表權限時出現 NullReferenceException (NullReferenceException when trying to set registry permissions with C#)

可執行腳本在 Linux 機器上獲得權限被拒絕 (Executable script gets permission denied on Linux box)

iOS Facebook 令牌權限生日 (iOS Facebook token Permissions birthday)

如何使 644 個權限文件可從 PHP 寫入? (How do I make 644 permission files writable from PHP?)

Android 6.0 中的權限更改回調 (Permission changed callback in Android 6.0)

LINQ和數據庫權限 (LINQ and Database Permissions)

多個用戶可以訪問/更新 Market 中的單個 Android 應用程序嗎? (Can multiple users access/update a single Android app in the Market?)

運行具有權限的 Eclipse 應用程序或小程序 (Running Eclipse aplication or applet with permissions)

通過 AirWatch 卸載 Android APK (Uninstall Android APK via AirWatch)







留言討論