SharePoint提升權限去執行程式

摘要:SharePoint提升權限去執行程式

在SharePoint執行一些程式時,有時候會發生因為登入者的權限不足,無法正確執行,參考一些相關文章,有兩種方式可以提升權限 :一種是利用轉換執行身份方式,一種是利用SPSecurity直接提高權限

  • 轉換執行身份

    使用SHAREPOINT\system的身份,開啟網站執行程式。 

    ※在測試時發現以SHAREPOINT管理員身分執行"新增清單庫"資料,Update()時會有例外發生,在執行所屬的SPWeb指定web.AllowUnsafeUpdates=true;即可。
  • SPSecurity.RunWithElevatedPrivileges : 將權限提升到 Full Control

寫法一 :

 

寫法二 : 自定方法

參考文件 :  

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

http://vspug.com/tanujashares/2007/08/07/impersonation-in-sharepoint-2007/