public void Delete(SPNavigationNodeInstance node)
        {
            if (node == null)
            {
                throw new JavaScriptException(Engine, "Error", "node must be specified.");
            }

            m_navigationNodeCollection.Delete(node.SPNavigationNode);
        }
Exemple #2
0
        private void CheckAndRemove(SPNavigationNodeCollection topNavi)
        {
            var nodes = from n in topNavi.Cast <SPNavigationNode>()
                        where n.Title.Equals("HR Department")
                        select n;

            if (nodes.Count() == 1)
            {
                topNavi.Delete(nodes.First());
            }
        }
Exemple #3
0
        private void ConfigTopNavigationBar(SPWeb web)
        {
            SPNavigationNodeCollection topnav = web.Navigation.TopNavigationBar;

            if (topnav.Count == 1 && topnav[0].Title == "Home" && topnav[0].Url == web.ServerRelativeUrl)
            {
                topnav.Delete(topnav[0]);

                string           linkTitle = web.Title;
                SPNavigationNode node      = new SPNavigationNode(linkTitle, web.ServerRelativeUrl);
                node = topnav.AddAsFirst(node);
            }
        }
 public static void DeleteLink(SPNavigationNodeCollection navigation, string title)
 {
     bool isUpdatesMade = true;
     while (isUpdatesMade)
     {
         isUpdatesMade = false;
         foreach (SPNavigationNode node in navigation)
         {
             if (node.Title == title)
             {
                 navigation.Delete(node);
                 isUpdatesMade = true;
             }
             DeleteLink(node.Children, title);
         }
     }
 }
Exemple #5
0
        public static void ProvisionWebStructure(this SPWeb web, WebDefinitionCollection subsites)
        {
            foreach (var site in subsites)
            {
                var existed = web.Webs.Cast <SPWeb>().Where(p => p.Url.Contains(site.Url)).FirstOrDefault();

                if (existed != null && !site.Overwrite)
                {
                    continue;
                }
                if (existed != null && site.Overwrite)
                {
                    DeleteSite(existed);
                }

                var newSite = web.AddSite(site.Url.Trim(), site.Name.Trim(), site.Template.Trim());
                if (newSite == null)
                {
                    continue;
                }
                //Provision Lists
                //Provision Features
                foreach (var feature in site.Features)
                {
                    newSite.Features.Add(feature.Guid);
                    //newSite.Update();
                }

                //BreakRoleInheritance
                if (site.BreakRoleInheritance)
                {
                    try
                    {
                        newSite.AllowUnsafeUpdates = true;

                        if (!newSite.HasUniqueRoleAssignments)
                        {
                            newSite.BreakRoleInheritance(false);
                        }

                        //create group
                        string groupOwners = site.Name.Trim() + " Owners";
                        newSite.CreateNewGroup(groupOwners, "Use this group to grant people full control permissions to the SharePoint site: " + site.Name.Trim(), SPRoleType.Administrator);

                        string groupMembers = site.Name.Trim() + " Members";
                        newSite.CreateNewGroup(groupMembers, "Use this group to grant people contribute permissions to the SharePoint site: " + site.Name.Trim(), SPRoleType.Contributor);

                        string groupVisitors = site.Name.Trim() + " Visitors";
                        newSite.CreateNewGroup(groupVisitors, "Use this group to grant people read permissions to the SharePoint site: " + site.Name.Trim(), SPRoleType.Reader);

                        newSite.Update();

                        Utility.ChangeSPGroupOwnerBySPGroup(newSite, groupOwners, groupOwners);
                        Utility.ChangeSPGroupOwnerBySPGroup(newSite, groupMembers, groupOwners);
                        Utility.ChangeSPGroupOwnerBySPGroup(newSite, groupVisitors, groupOwners);

                        SPUser authenUsers = newSite.EnsureUser("NT AUTHORITY\\authenticated users");
                        if (authenUsers != null)
                        {
                            SPGroup spGrp = newSite.Groups[groupVisitors];
                            if (spGrp != null)
                            {
                                spGrp.AddUser(authenUsers);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        newSite.AllowUnsafeUpdates = false;
                    }
                }


                //provision Top Navigation Bar
                try
                {
                    newSite.AllowUnsafeUpdates = true;

                    SPNavigationNodeCollection topnav = newSite.Navigation.TopNavigationBar;

                    //clear all
                    for (int i = topnav.Count - 1; i >= 0; i--)
                    {
                        topnav.Delete(topnav[i]);
                    }

                    string           linkTitle = newSite.Title;
                    SPNavigationNode node      = new SPNavigationNode(linkTitle, newSite.ServerRelativeUrl);
                    node = topnav.AddAsLast(node);

                    SPWeb            rootWeb       = web.Site.RootWeb;
                    string           linkRootTitle = rootWeb.Title;
                    SPNavigationNode nodeRoot      = new SPNavigationNode(linkRootTitle, rootWeb.ServerRelativeUrl);
                    nodeRoot = topnav.AddAsFirst(nodeRoot);

                    //AddParentNode(newSite, topnav);
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    newSite.AllowUnsafeUpdates = false;
                }

                if (site.SubSites.Count > 0)
                {
                    newSite.ProvisionWebStructure(site.SubSites);
                }
            }
        }