Elevate Permissions To Modify User Profile

We can using the following code to elevate permissions to modify user profile:

 1 try
2 {
3 SPSecurity.RunWithElevatedPrivileges(delegate()
4 {
5 HttpContext curcon = HttpContext.Current;
6 using (SPSite mySite = new SPSite("http://YourSiteURL"))
7 {
8 SPServiceContext context = SPServiceContext.GetContext(mySite);
9 HttpContext.Current = null;
10 UserProfileManager upm = new UserProfileManager(context, true);
11 UserProfile userpro = upm.GetUserProfile(userLoginName);
12
13 //modify the value of some properties,change the old value to your value
14 userpro["PropertyName"].Value = yourvalue;
15
16 userpro.Commit();
17 }
18 HttpContext.Current = curcon;
19 });
20 }
21 catch (Exception ex)
22 {
23 //throw some exceptions
24 }

 

作者:Statmoon
         
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
posted @ 2012-03-05 16:18  Statmoon  阅读(242)  评论(0编辑  收藏  举报