Wednesday, December 10, 2014

Adding Target audience to sharepoint left navigation programatically

SPNavigationNodeCollection nodeColl = newSite.Navigation.QuickLaunch;
 
                                            SPGroupCollection groups = newSite.Groups;
                                            string groupnamesString = ";;;;";
                                            foreach (SPGroup group in groups)
                                            {
                                                if (group.Name.Contains("Owner") || group.Name.Contains("Member"))
                                                    groupnamesString += group.Name + ",";
                                            }
 
                                            //groupnamesString = groupnamesString.Substring(0, groupnamesString.Length - 1);
                                            //node.Properties.Add("Audience",  ";;;;" + Group1+","+ Group2 +","+ Group3+","+etc... "" );
                                            Console.WriteLine(groupnamesString);
 
                                            if (!string.IsNullOrEmpty(groupnamesString))
                                            {
                                                foreach (SPNavigationNode node in nodeColl)
                                                {
                                                    if (node.IsExternal == true && node.Title != "General")
                                                    {
                                                        if (node.Properties.ContainsKey("Audience"))
                                                        {
                                                            node.Properties["Audience"] = groupnamesString;
                                                        }
                                                        else
                                                        {
                                                            node.Properties.Add("Audience", groupnamesString);
                                                        }
                                                        node.Update();
                                                    }
                                                }
                                                newSite.Update();
                                            }

No comments:

Post a Comment

Image noise comparison methods

 1. using reference image technique     - peak_signal_noise_ratio (PSNR)     - SSI 2. non-reference image technique     - BRISQUE python pac...