Monday 22 December 2014


  1. Enable to SharePoint User Information List

  2. protected void EnableUSIList(object sender, EventArgs e)   
  3. {   
  4.       try   
  5.       {   
  6.             string strFields = "";   
  7.             //Context.Response.Output.Write("Clicked Me!");   
  8.             SPSite Site = SPContext.Current.Site;   
  9.             Context.Response.Output.Write(Site + "<br/>");   
  10.             using (SPWeb Web = Site.OpenWeb())   
  11.             {   
  12.                   Web.AllowUnsafeUpdates = true;   
  13.                   SPList List = Web.Lists["User Information List"];   
  14.                   Context.Response.Output.Write(List.ToString() + "<br/>");   
  15.                   List.Hidden = false;   
  16.                   List.Update();   
  17.                   Web.AllowUnsafeUpdates = false;   
  18.                   Context.Response.Output.Write(List.Hidden.ToString() + "<br/>");   
  19.   
  20.             }   
  21.       }   

  22.       catch (Exception ex)   
  23.       {   
  24.             Context.Response.Output.Write("Errors: " + ex.Message.ToString());   
  25.       }   
  26.   
  27. }  

Get Programmatically Profile Picture Url from User Information List of Sharepoint


  1. try       
  2.   
  3. {  
  4.   
  5.       string LoginName = string.Empty;  
  6.   
  7.       string SiteUrl = SPContext.Current.Site.Url;  
  8.   
  9.       string Username = SPContext.Current.Web.CurrentUser.LoginName;  
  10.   
  11.       SPSite Site = new SPSite(SiteUrl);  
  12.   
  13.       string data = string.Empty;  
  14.   
  15.       using (SPWeb Web = Site.OpenWeb())  
  16.       {  
  17.   
  18.              SPList List = Web.Lists["User Information List"];  
  19.   
  20.              SPQuery Query = new SPQuery();  
  21.   
  22.              Query.Query = "<Where><Eq><FieldRef Name = 'ID'/><Value Type='Text'>"+Username+"</Value></Eq></Where>";  
  23.   
  24.              SPListItemCollection ItemCollection;  
  25.   
  26.              ItemCollection = List.GetItems(Query);  
  27.   
  28.              if (ItemCollection.Count > 0)  
  29.              {  
  30.   
  31.                    foreach(SPListItem ListItem in ItemCollection)  
  32.                    {  
  33.   
  34.                           if(ListItem["Picture"] != null)  
  35.                           {  
  36.   
  37.                                data = ListItem["Picture"].ToString();  
  38.   
  39.                           }  
  40.   
  41.                     }  
  42.   
  43.               }  
  44.   
  45.         }         
  46.   
  47. }         
  48.   
  49. catch(Exception ex)       
  50. {  
  51.   
  52.      Context.Response.Output.Write("Error : " + ex.Message.ToString());        
  53.   
  54. }  

No comments:

Post a Comment