/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private static void impersonateTest() { string siteStr = "http://mysharepointsite/"; SPUserToken systoken = tempSite.SystemAccount.UserToken; { using (SPWeb web = site.OpenWeb()) { //right now, logged in as Site System Account Console.WriteLine("Currently logged in as: " + web.CurrentUser.ToString()); switchUser(web, siteStr, "BlackNinjaSoftware/MatthewCarriere"); switchUser(web, siteStr, "BlackNinjaSoftware/ShereenQumsieh"); switchUser(web, siteStr, "BlackNinjaSoftware/DonabelSantos"); } } } private static void switchUser(SPWeb web, string siteStr, string user) { //impersonate somebody else SPUserToken userToken = web.AllUsers[user].UserToken; SPWeb w = s.OpenWeb(); Console.WriteLine("Currently logged in as: " + w.CurrentUser.ToString() + "(" + w.CurrentUser.Name + ")" ); }
URL: http://blackninjasoftware.com/tag/sharepoint-object-model/