MOSS 2007 - Working with SPSecurity, SPList Item Objects



Cheat Sheet to create site link for the Group programatically

        /// Method to create site link for the Group programatically
        /// Created  By :Hima
        /// Created On:  Feb 05 2010
        /// Copy right :SyntaxHelp
        /// 
        /// 
        /// 
        /// 
        /// 
        private static string CreateSiteLink(SPWeb newSite, int groupId, string text)
        {
            string retVal = "";
            SPWeb elevatedRootWeb = null;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite elevatedSite = new SPSite(newSite.Site.ID))
                {
                    elevatedRootWeb = elevatedSite.RootWeb;
                }

            });
            SPList userInformation = elevatedRootWeb.Lists["User Information List"];
            if (userInformation != null)
            {
          elevatedRootWeb.AllowUnsafeUpdates = true;

                SPListItem item = userInformation.GetItemById(groupId);
                if (item["Notes"] != null)
                {
                    item["Notes"] = string.Format(text, newSite.ServerRelativeUrl, newSite.Name);
                    item.Update();
                }
                elevatedRootWeb.AllowUnsafeUpdates = false;
            }
            else
                retVal = " Site link for the group " + groupId + " Cannot be Created. (User Information List not found)";           
            return retVal;            
        } 

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.