public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPWeb web = (SPWeb)properties.Feature.Parent; SPNavigationNodeCollection topNavi = web.Navigation.TopNavigationBar; CheckAndRemove(topNavi); }
/// <summary> /// /// </summary> /// <param name="iChildrenCount"></param> /// <param name="userLoginName"></param> /// <param name="ChildrenNodes"></param> /// <param name="htmlul"></param> private void CreateNewOptionsToMenuForNavigation(ref Int64 iChildrenCount, string userLoginName, SPNavigationNodeCollection ChildrenNodes,ref HtmlGenericControl htmlul) { try { HtmlGenericControl htmlh2SubGroup = new HtmlGenericControl("h2"); HtmlGenericControl htmlliSubGroup = new HtmlGenericControl("li"); htmlliSubGroup.Attributes.Add("class", "heading"); htmlh2SubGroup.Controls.Add(CreateAnchor("", ChildrenNodes.Parent.Title, "", "parent")); htmlliSubGroup.Controls.Add(htmlh2SubGroup); htmlul.Attributes.Add("class", "simple"); htmlul.Controls.Add(htmlliSubGroup); foreach (SPNavigationNode node in ChildrenNodes) { if (clsCommonBL.IsUserHasAccess(node.Url, userLoginName)) { HtmlGenericControl htmlli = new HtmlGenericControl("li"); HtmlAnchor htmlAnchor = new HtmlAnchor(); htmlli.Controls.AddAt(0, CreateAnchor(node.Url, node.Title,node.Title, string.Empty)); ////Children Count ++iChildrenCount; htmlul.Controls.Add(htmlli); } } } catch (Exception ex) { throw; } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { //Get The Quick Launch and add a new root node if it doesn't already exist SPNavigationNodeCollection quickLinkNodes = ((SPWeb)(properties.Feature.Parent)).Navigation.QuickLaunch; SPNavigationNode rootNode = quickLinkNodes[0]; if (rootNode.Title != rootNodeTitle) { rootNode = new SPNavigationNode(rootNodeTitle, ((SPWeb)(properties.Feature.Parent)).Url, false); quickLinkNodes.AddAsFirst(rootNode); } //Delete Items if they already exist foreach (SPNavigationNode quickLinkNode in rootNode.Children) { quickLinkNode.Delete(); } //Add the Custom Links based on the Dictionary foreach (KeyValuePair <string, string> kvp in GetNav()) { // add security trimmed nodes, set all to external=false var newNode = new SPNavigationNode(kvp.Key, kvp.Value, false); rootNode.Children.AddAsLast(newNode); } quickLinkNodes.Parent.Update(); }
public static SPNavigationNode GetNavNode(SPNavigationNodeCollection navNode, string navField, string nodename, SPListItem oLiParent) { try { var navs = oLiParent[oLiParent.ParentList.Fields.GetFieldByInternalName(navField).Id].ToString().Split(','); foreach (SPNavigationNode ndNav in navNode) { if (string.Equals(ndNav.Title, nodename, StringComparison.InvariantCultureIgnoreCase)) { foreach (var nav in navs) { if (ndNav.Id == int.Parse(nav)) { return(ndNav); } } } } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } return(null); }
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSite siteCollection = properties.Feature.Parent as SPSite; if (siteCollection != null) { SPWeb site = siteCollection.RootWeb; try { // delete folder of site pages provisioned during activation SPFolder sitePagesFolder = site.GetFolder("WingtipPages"); sitePagesFolder.Delete(); } catch { } SPNavigationNodeCollection topNav = site.Navigation.TopNavigationBar; for (int i = topNav.Count - 1; i >= 0; i--) { if (topNav[i].Url.Contains("WingtipPages")) { // delete node topNav[i].Delete(); } } } }
//private static void CreateRootFolder(SPWeb curweb, string folderName, string folderDescription) //{ // curweb.Lists.Add(folderName, folderDescription, SPListTemplateType.DocumentLibrary); // curweb.RootFolder //} // Uncomment the method below to handle the event raised before a feature is deactivated. private static void CreateSiteNavigation(SPFeatureReceiverProperties prop) { SPSite site = prop.Feature.Parent as SPSite; SPWeb rootWeb = site.RootWeb; SPNavigationNodeCollection topNavNodes = rootWeb.Navigation.TopNavigationBar; SPNavigationNode node = new SPNavigationNode("DashboardNav", "", true); topNavNodes.AddAsLast(node); SPNavigationNode oNewNode = new SPNavigationNode("Org Browser", ""); rootWeb.Navigation.TopNavigationBar.AddAsLast(oNewNode); oNewNode.Properties.Add("NodeType", "Heading"); oNewNode.Update(); SPNavigationNode oChild1 = new SPNavigationNode("Official", ""); oNewNode.Children.AddAsFirst(oChild1); oChild1.Properties.Add("NodeType", "Heading"); oChild1.Update(); // rootWeb.Navigation.UseShared = false; rootWeb.Update(); //SPNavigationNode oNewNode = new SPNavigationNode("Org Browser", ""); //rootWeb.Navigation.TopNavigationBar.AddAsLast(oNewNode); //oNewNode.Properties.Add("NodeType", "Heading"); //oNewNode.Update(); }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWeb site = properties.Feature.Parent as SPWeb; SPNavigationNodeCollection topNav = site.Navigation.TopNavigationBar; SPNavigationNode navNode = new SPNavigationNode("Wingtip Silverlight Product Browser", "_layouts/MSDN.WingtipProductBrowser/ProductBrowser.aspx"); topNav.AddAsLast(navNode); }
public static void AddNavigationForPage(SPWeb web, SPFile page, string linkName) { SPNavigationNodeCollection navItems = web.Navigation.QuickLaunch; SPNavigationNode newNode = new SPNavigationNode(linkName, page.Url, false); navItems.AddAsFirst(newNode); web.Update(); }
private void LoadTopNavBarNodeCollInMemory() { if (!_web.Navigation.UseShared) { SPNavigationNodeCollection nav = _web.Navigation.QuickLaunch; _web.AllowUnsafeUpdates = true; // get the list of quick launch nodes // configured for particular app List <int> quickLaunchNavIds = null; if (_appId != -1) { quickLaunchNavIds = appHelper.TryGetQuickLaunchIdsByAppId(_appId); } string onclick = string.Empty; foreach (SPNavigationNode node in nav) { if (_appId != -1) { if (quickLaunchNavIds != null && quickLaunchNavIds.Contains(node.Id)) { onclick = "QLOpenUrlWithModal('/_layouts/epmlive/customeditnav.aspx?ID=" + node.Id + "&nodetype=quiklnch&appId=" + _appId.ToString() + "', 'Edit Quick Launch Nav');"; _alLinkData.Add(new Triplet(node.Title, onclick, true)); if (node.Children.Count > 0) { foreach (SPNavigationNode childNode in node.Children) { if (quickLaunchNavIds != null && quickLaunchNavIds.Contains(childNode.Id)) { onclick = "QLOpenUrlWithModal('/_layouts/epmlive/customeditnav.aspx?ID=" + childNode.Id + "&nodetype=quiklnch&appId=" + _appId.ToString() + "', 'Edit Quick Launch Nav');"; _alLinkData.Add(new Triplet(childNode.Title, onclick, false)); } } } } } else { _alLinkData.Add(new Triplet(node.Title, _web.ServerRelativeUrl + "/_layouts/epmlive/customeditnav.aspx?nodetype=quiklnch&id=" + node.Id, true)); if (node.Children.Count > 0) { foreach (SPNavigationNode childNode in node.Children) { if (quickLaunchNavIds != null && quickLaunchNavIds.Contains(childNode.Id)) { _alLinkData.Add(new Triplet(childNode.Title, _web.ServerRelativeUrl + "/_layouts/epmlive/customeditnav.aspx?nodetype=quiklnch&id=" + childNode.Id, false)); } } } } } _web.AllowUnsafeUpdates = false; } }
public SPNavigationNodeCollectionInstance(ObjectInstance prototype, SPNavigationNodeCollection navigationNodeCollection) : this(prototype) { if (navigationNodeCollection == null) { throw new ArgumentNullException("navigationNodeCollection"); } m_navigationNodeCollection = navigationNodeCollection; }
private void LoadTopNavBarNodeCollInMemory() { if (!_web.Navigation.UseShared) { SPNavigationNodeCollection nav = _web.Navigation.TopNavigationBar; _web.AllowUnsafeUpdates = true; List <int> topNavIds = null; if (_appId != -1) { topNavIds = appHelper.TryGetTopNavIdsByAppId(_appId); } string onclick = string.Empty; foreach (SPNavigationNode node in nav) { if (_appId != -1) { if (topNavIds != null && topNavIds.Contains(node.Id)) { onclick = "TNOpenUrlWithModal('/_layouts/epmlive/customeditnav.aspx?ID=" + node.Id + "&nodetype=topnav&appId=" + _appId.ToString() + "', 'Edit Top Nav');"; _alLinkData.Add(new Triplet(node.Title, onclick, true)); if (node.Children.Count > 0) { foreach (SPNavigationNode childNode in node.Children) { if (topNavIds != null && topNavIds.Contains(childNode.Id)) { onclick = "TNOpenUrlWithModal('/_layouts/epmlive/customeditnav.aspx?ID=" + childNode.Id + "&nodetype=topnav&appId=" + _appId.ToString() + "', 'Edit Top Nav');"; _alLinkData.Add(new Triplet(childNode.Title, onclick, false)); } } } } } else { _alLinkData.Add(new Triplet(node.Title, _web.Url + "/_layouts/epmlive/customeditnav.aspx?ID=" + node.Id + "&nodetype=topnav", true)); if (node.Children.Count > 0) { foreach (SPNavigationNode childNode in node.Children) { if (topNavIds != null && topNavIds.Contains(childNode.Id)) { _alLinkData.Add(new Triplet(childNode.Title, _web.Url + "/_layouts/epmlive/customeditnav.aspx?ID=" + childNode.Id + "&nodetype=topnav", false)); } } } } } _web.AllowUnsafeUpdates = false; } }
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()); } }
public QuickLaunchHelper(SPWeb web) { nodes = web.Navigation.QuickLaunch; // before create new delete all old items // leave 02 node cannot be deleted for (int i = nodes.Count - 1; i >= 0; i--) { nodes[i].Delete(); } }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite siteCollection = properties.Feature.Parent as SPSite; if (siteCollection != null) { SPWeb site = siteCollection.RootWeb; SPNavigationNodeCollection topNav = site.Navigation.TopNavigationBar; topNav.AddAsLast(new SPNavigationNode("DataGrid", "SitePages/DataGridPage.aspx")); } }
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); } }
// Uncomment the method below to handle the event raised before a feature is deactivated. public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPWeb site = properties.Feature.Parent as SPWeb; SPNavigationNodeCollection topNav = site.Navigation.TopNavigationBar; for (int i = topNav.Count - 1; i > 0; i--) { if (topNav[i].Title == "Wingtip Silverlight Product Browser") { topNav[i].Delete(); } } }
private static void AddParentNode(SPWeb web, SPNavigationNodeCollection topnav) { SPWeb parentWeb = web.ParentWeb; string linkTitle = parentWeb.Title; SPNavigationNode node = new SPNavigationNode(linkTitle, parentWeb.ServerRelativeUrl); node = topnav.AddAsFirst(node); if (!parentWeb.IsRootWeb) { AddParentNode(parentWeb, topnav); } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite siteCollection = properties.Feature.Parent as SPSite; if (siteCollection != null) { SPWeb site = siteCollection.RootWeb; // create menu items on top link bar for custom site pages SPNavigationNodeCollection topNav = site.Navigation.TopNavigationBar; topNav.AddAsLast(new SPNavigationNode("Page 1", "WingtipPages/Page1.aspx")); topNav.AddAsLast(new SPNavigationNode("Page 2", "WingtipPages/Page2.aspx")); topNav.AddAsLast(new SPNavigationNode("Page 3", "WingtipPages/Page3.aspx")); } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite siteCollection = (SPSite)properties.Feature.Parent; SPWeb site = siteCollection.RootWeb; // create dropdown menu for custom site pages SPNavigationNodeCollection topNav = site.Navigation.TopNavigationBar; SPNavigationNode DropDownMenu1 = topNav.AddAsLast(new SPNavigationNode("Web Parts 101", "")); DropDownMenu1.Children.AddAsLast(new SPNavigationNode("Web Part 1", "WebPartPages/WebPart1.aspx")); DropDownMenu1.Children.AddAsLast(new SPNavigationNode("Web Part 2", "WebPartPages/WebPart2.aspx")); DropDownMenu1.Children.AddAsLast(new SPNavigationNode("Web Part 3", "WebPartPages/WebPart3.aspx")); DropDownMenu1.Children.AddAsLast(new SPNavigationNode("Web Part 4", "WebPartPages/WebPart4.aspx")); DropDownMenu1.Children.AddAsLast(new SPNavigationNode("Web Part 5", "WebPartPages/WebPart5.aspx")); SPNavigationNode DropDownMenu2 = topNav.AddAsLast(new SPNavigationNode("Web Part Samples", "")); DropDownMenu2.Children.AddAsLast(new SPNavigationNode("Custom Properties", "WebPartPages/CustomProperties.aspx")); DropDownMenu2.Children.AddAsLast(new SPNavigationNode("Web Part Verbs", "WebPartPages/WebPartVerbs.aspx")); DropDownMenu2.Children.AddAsLast(new SPNavigationNode("Web Part Connections", "WebPartPages/WebPartConnections.aspx")); DropDownMenu2.Children.AddAsLast(new SPNavigationNode("Web Parts Preconnected", "WebPartPages/WebPartsPreconnected.aspx")); DropDownMenu2.Children.AddAsLast(new SPNavigationNode("Async Web Part Demo", "WebPartPages/AsyncDemoWebPart.aspx")); SPFile page = site.GetFile("WebPartPages/WebPartsPreconnected.aspx"); SPLimitedWebPartManager mgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared); FontConnectionProvider.FontConnectionProvider ProviderWebPart = new FontConnectionProvider.FontConnectionProvider(); ProviderWebPart.Title = "Left Brain"; ProviderWebPart.UserGreeting = "I look pretty"; ProviderWebPart.TextFontSize = 18; ProviderWebPart.TextFontColor = "Green"; mgr.AddWebPart(ProviderWebPart, "Left", 0); FontConnectionConsumer.FontConnectionConsumer ConsumerWebPart = new FontConnectionConsumer.FontConnectionConsumer(); ConsumerWebPart.Title = "Right Brain"; ConsumerWebPart.UserGreeting = "And so do I"; mgr.AddWebPart(ConsumerWebPart, "Right", 0); mgr.SPConnectWebParts( ProviderWebPart, mgr.GetProviderConnectionPoints(ProviderWebPart).Default, ConsumerWebPart, mgr.GetConsumerConnectionPoints(ConsumerWebPart).Default ); }
/// <summary> /// reads a set of integers /// that represents a recorded node movement and /// perform the node re-ordering /// </summary> /// <param name="movementInfo"></param> private void MoveNode(string[] movementInfo) { int parentNodeID = Convert.ToInt32(movementInfo[0]); int oldIndex = Convert.ToInt32(movementInfo[1]); //if (_appId != -1) //{ // // translate displayed index into real index in Web.Navigation // oldIndex = AppSettingsHelper.GetRealIndex(parentNodeID, oldIndex, _appId, _nodeType); //} int newIndex = Convert.ToInt32(movementInfo[2]); //if (_appId != -1) //{ // // translate displayed index into real index in Web.Navigation // newIndex = AppSettingsHelper.GetRealIndex(parentNodeID, newIndex, _appId, "topnav"); //} SPNavigationNode parentNode = _web.Navigation.GetNodeById(parentNodeID); SPNavigationNodeCollection contextNodeCollection = parentNode.Children; SPNavigationNode node = contextNodeCollection[oldIndex]; int currentlastIndex = contextNodeCollection.Count - 1; if (newIndex != oldIndex) { if (newIndex == 0) { node.MoveToFirst(contextNodeCollection); } else if (newIndex == currentlastIndex) { node.MoveToLast(contextNodeCollection); } else { if (newIndex < oldIndex) { node.Move(contextNodeCollection, contextNodeCollection[newIndex - 1]); } else { node.Move(contextNodeCollection, contextNodeCollection[newIndex]); } } } // note: // when performing SPNavigationNode.(Move/MoveToFirst/MoveToLast) // SPNavigationNode.Update() is not necessary according to MSDN documents }
protected virtual SPNavigationNode LookupNavigationNode(SPNavigationNodeCollection nodes, NavigationNodeDefinitionBase definition) { var currentNode = nodes .OfType <SPNavigationNode>() .FirstOrDefault(n => !string.IsNullOrEmpty(n.Title) && (n.Title.ToUpper() == definition.Title.ToUpper())); if (currentNode == null) { currentNode = nodes .OfType <SPNavigationNode>() .FirstOrDefault(n => !string.IsNullOrEmpty(n.Url) && (n.Url.ToUpper().EndsWith(definition.Url.ToUpper()))); } return(currentNode); }
public QuickLaunchHelper(SPWeb web, bool isInheritTopLinkBarOfParent) { nodes = web.Navigation.QuickLaunch; // before create new delete all old items // leave 02 node cannot be deleted for (int i = nodes.Count - 1; i >= 0; i--) { nodes[i].Delete(); } if (isInheritTopLinkBarOfParent && !web.IsRootWeb) web.Navigation.UseShared = true; }
private static void RemoveNavigationEntries(SPWeb _root) { try { SPNavigationNodeCollection topNav = _root.Navigation.TopNavigationBar; for (int i = topNav.Count - 1; i >= 0; i--) { topNav[i].Delete(); } } catch (Exception ex) { throw new ApplicationException("Cannot remove navigation entries: " + ex.Message); } }
/// <summary> /// Occurs after a Feature is activated. /// </summary> /// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties" /> object that represents the properties of the event.</param> /// <exception cref="System.ApplicationException"> /// In FeatureActivated the Site is null /// or /// </exception> public override void FeatureActivated(SPFeatureReceiverProperties properties) { string _cp = "Starting"; try { SPSite site = (SPSite)properties.Feature.Parent; if (site == null) { throw new ApplicationException("In FeatureActivated the Site is null"); } using (EntitiesDataContext _edc = new EntitiesDataContext(site.RootWeb.Url)) { Anons.WriteEntry(_edc, m_SourceClass + m_SourceFeatureActivated, "FeatureActivated strating"); _cp = "ReplaceMasterMage"; ReplaceMasterMage(site); Anons.WriteEntry(_edc, m_SourceClass + m_SourceFeatureActivated, "Navigation setup starting"); _cp = "SPNavigationNodeCollection"; SPNavigationNodeCollection _topNav = site.RootWeb.Navigation.TopNavigationBar; _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuVendorTitle, ProjectElementManagement.URLVendorDashboard)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuInboundOwnerTitle, ProjectElementManagement.URLInboundOwner)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuViewInboundsTitle, ProjectElementManagement.URLViewInbounds)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuViewOutboundsTitle, ProjectElementManagement.URLViewOutbounds)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuOutboundOwnerTitle, ProjectElementManagement.URLOutboundOwner)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuOutboundCoordinatorTitle, ProjectElementManagement.URLOutboundCoordinator)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuForwarderTitle, ProjectElementManagement.URLForwarderDashboard)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuSecurityEscortProviderTitle, ProjectElementManagement.URLSecurityEscortProviderDashboard)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuSecurityGateTitle, ProjectElementManagement.URLGateDashboard)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuOperatorTitle, ProjectElementManagement.URLOperator)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuSupervisorTitle, ProjectElementManagement.URLSupervisor)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuDriversTitle, ProjectElementManagement.URLDrivers)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuTrucksTitle, ProjectElementManagement.URLTrucks)); _topNav.AddAsLast(new SPNavigationNode(ProjectElementManagement.MenuTrailersTitle, ProjectElementManagement.URLTrailers)); foreach (SPNavigationNode item in _topNav) { item.Update(); } //WebPartPages.ProjectElementManagement.SetupConnections(_edc, _root); _cp = "Entities.Anons"; Anons.WriteEntry(_edc, m_SourceClass + m_SourceFeatureActivated, "FeatureActivated finished"); } } catch (Exception ex) { throw new ApplicationException(String.Format("FeatureActivated exception at {0}: {1}", _cp, ex.Message)); } }
/// <summary> /// Adds the on quick launch bar. /// </summary> /// <param name="web">The web.</param> public void AddOnQuickLaunchBar(SPWeb web) { using (SPWeb rootWeb = web.Site.OpenWeb()) { SPNavigationNodeCollection nodes = rootWeb.Navigation.QuickLaunch; SPNavigationNode navNode = new SPNavigationNode(web.Title, web.ServerRelativeUrl, false); foreach (SPNavigationNode node in nodes) { if (node.Id == 1026) { node.Children.AddAsLast(navNode); break; } } } }
// Uncomment the method below to handle the event raised before a feature is deactivated. public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSite siteCollection = properties.Feature.Parent as SPSite; if (siteCollection != null) { SPWeb site = siteCollection.RootWeb; SPNavigationNodeCollection topNav = site.Navigation.TopNavigationBar; for (int i = topNav.Count - 1; i >= 0; i--) { if (topNav[i].Url.Contains("DataGridPage")) { topNav[i].Delete(); } } } }
public virtual void DeleteNodesByMatch(DeleteNavigationNodesDefinitionBase typedDefinition, SPNavigationNodeCollection nodesCollection, Func<string, string> resolveTokenizedUrlAction) { var allNodes = nodesCollection.OfType<SPNavigationNode>() .ToArray(); var nodesToDelete = FindMatches(allNodes, typedDefinition, resolveTokenizedUrlAction); if (nodesToDelete.Any()) { foreach (var node in nodesToDelete.ToArray()) { node.Delete(); } } }
private static SPWeb CreateSite(SPSite Col, uint locale, string template, string SiteName) { SPWeb root = Col.RootWeb; SPWeb web = root.Webs.Add(SiteName, SiteName, "Demo Description", locale, template, true, false); // add navigation SPNavigation navRoot = root.Navigation; SPNavigationNodeCollection navQL = navRoot.QuickLaunch; var newNav = new SPNavigationNode(web.Title, web.ServerRelativeUrl); navQL.Add(newNav, newNav); // alternative // web.QuickLaunchEnabled = true; return(web); }
public virtual void DeleteNodesByMatch(DeleteNavigationNodesDefinitionBase typedDefinition, SPNavigationNodeCollection nodesCollection, Func <string, string> resolveTokenizedUrlAction) { var allNodes = nodesCollection.OfType <SPNavigationNode>() .ToArray(); var nodesToDelete = FindMatches(allNodes, typedDefinition, resolveTokenizedUrlAction); if (nodesToDelete.Any()) { foreach (var node in nodesToDelete.ToArray()) { node.Delete(); } } }
public QuickLaunchHelper(SPWeb web, bool isInheritTopLinkBarOfParent) { nodes = web.Navigation.QuickLaunch; // before create new delete all old items // leave 02 node cannot be deleted for (int i = nodes.Count - 1; i >= 0; i--) { nodes[i].Delete(); } if (isInheritTopLinkBarOfParent && !web.IsRootWeb) { web.Navigation.UseShared = true; } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { if (properties.Feature.Parent is SPSite) { // cannot activate this feature on site level return; } SPWeb web = (SPWeb)properties.Feature.Parent; SPNavigationNodeCollection topNavi = web.Navigation.TopNavigationBar; // Check existing top element. If present remove first CheckAndRemove(topNavi); // Read navigation instruction XNamespace siteNM = "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"; using (Stream st = GetType().Assembly.GetManifestResourceStream("ApplicationPage.web.sitemap")) { using (XmlReader tr = new XmlTextReader(st)) { try { XElement siteMap = XElement.Load(tr); // add nodes var root = from r in siteMap.Descendants() where r.Attribute("title").Value.Equals("HR Department") select r; // Found if (root.Count() == 1) { XElement rootElement = root.First(); string rootPath = web.Url + PATH; // create and add rootnode SPNavigationNode rootNode = new SPNavigationNode( rootElement.Attribute("title").Value, rootPath + rootElement.Attribute("url").Value, true); SPNavigationNode topNode = topNavi.AddAsLast(rootNode); AddNodes(rootElement, topNode, rootPath); } } catch (Exception ex) { } } } }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { try { SPSite siteCollection = properties.Feature.Parent as SPSite; if (siteCollection != null) { SPWeb site = siteCollection.RootWeb; SPNavigationNodeCollection topNav = site.Navigation.TopNavigationBar; topNav.AddAsLast(new SPNavigationNode("DataGrid-Updated", "SitePages/DataGridPage.aspx")); } } catch (Exception ex) { SPUtility.LogCustomAppError(ex.Message + "\n" + ex.StackTrace); } }
protected virtual SPNavigationNode LookupNavigationNode(SPNavigationNodeCollection nodes, NavigationNodeDefinitionBase definition) { var currentNode = nodes .OfType <SPNavigationNode>() .FirstOrDefault(n => !string.IsNullOrEmpty(n.Title) && (n.Title.ToUpper() == definition.Title.ToUpper())); if (currentNode == null) { var url = ResolveTokenizedUrl(CurrentWebModelHost, definition); url = HttpUtility.UrlDecode(url); currentNode = nodes .OfType <SPNavigationNode>() .FirstOrDefault(n => !string.IsNullOrEmpty(n.Url) && (n.Url.ToUpper().EndsWith(url.ToUpper()))); } return(currentNode); }
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); } } }
/// <summary> /// Adds the nodes. /// </summary> /// <param name="pubWeb">The publishing web.</param> /// <param name="isGlobal">if set to <c>true</c> [is global].</param> /// <param name="existingNodes">The existing nodes.</param> /// <param name="newNodes">The new nodes.</param> private static void AddNodes(PublishingWeb pubWeb, bool isGlobal, SPNavigationNodeCollection existingNodes, XmlNodeList newNodes) { if (newNodes.Count == 0) return; for (int i = 0; i < newNodes.Count; i++) { XmlElement newNodeXml = (XmlElement)newNodes[i]; string url = newNodeXml.SelectSingleNode("Url").InnerText; string title = newNodeXml.GetAttribute("Title"); NodeTypes type = NodeTypes.None; if (newNodeXml.SelectSingleNode("NodeType") != null && !string.IsNullOrEmpty(newNodeXml.SelectSingleNode("NodeType").InnerText)) type = (NodeTypes)Enum.Parse(typeof(NodeTypes), newNodeXml.SelectSingleNode("NodeType").InnerText); bool isVisible = true; if (!string.IsNullOrEmpty(newNodeXml.GetAttribute("IsVisible"))) isVisible = bool.Parse(newNodeXml.GetAttribute("IsVisible")); if (type == NodeTypes.Area) { // You can't just add an "Area" node (which represents a sub-site) to the current web if the // url does not correspond with an actual sub-site (the code will appear to work but you won't // see anything when you load the page). So we need to check and see if the node actually // points to a sub-site - if it does not then change it to "AuthoredLinkToWeb". SPWeb web = null; try { string name = url.Trim('/'); if (name.Length != 0 && name.IndexOf("/") > 0) { name = name.Substring(name.LastIndexOf('/') + 1); } try { // pubWeb.Web.Webs[] does not return null if the item doesn't exist - it simply throws an exception (I hate that!) web = pubWeb.Web.Webs[name]; } catch (ArgumentException) { } if (web == null || !web.Exists || web.ServerRelativeUrl.ToLower() != url.ToLower()) { // The url doesn't correspond with a sub-site for the current web so change the node type. // This is most likely due to copying navigation elements from another site type = NodeTypes.AuthoredLinkToWeb; } else if (web.Exists && web.ServerRelativeUrl.ToLower() == url.ToLower()) { // We did find a matching sub-site so now we need to set the visibility if (isVisible) pubWeb.Navigation.IncludeInNavigation(isGlobal, web.ID); else pubWeb.Navigation.ExcludeFromNavigation(isGlobal, web.ID); } } finally { if (web != null) web.Dispose(); } } else if (type == NodeTypes.Page) { // Adding links to pages has the same limitation as sub-sites (Area nodes) so we need to make // sure it actually exists and if it doesn't then change the node type. PublishingPage page = null; try { // Note that GetPublishingPages()[] does not return null if the item doesn't exist - it simply throws an exception (I hate that!) page = pubWeb.GetPublishingPages()[url]; } catch (ArgumentException) { } if (page == null) { // The url doesn't correspond with a page for the current web so change the node type. // This is most likely due to copying navigation elements from another site type = NodeTypes.AuthoredLinkToPage; url = pubWeb.Web.Site.MakeFullUrl(url); } else { // We did find a matching page so now we need to set the visibility if (isVisible) pubWeb.Navigation.IncludeInNavigation(isGlobal, page.ListItem.UniqueId); else pubWeb.Navigation.ExcludeFromNavigation(isGlobal, page.ListItem.UniqueId); } } // If it's not a sub-site or a page that's part of the current web and it's set to // not be visible then just move on to the next (there is no visibility setting for // nodes that are not of type Area or Page). if (!isVisible && type != NodeTypes.Area && type != NodeTypes.Page) continue; // Finally, can add the node to the collection. SPNavigationNode node = SPNavigationSiteMapNode.CreateSPNavigationNode( title, url, type, existingNodes); // Now we need to set all the other properties foreach (XmlElement property in newNodeXml.ChildNodes) { // We've already set these so don't set them again. if (property.Name == "Url" || property.Name == "Node" || property.Name == "NodeType") continue; // CreatedDate and LastModifiedDate need to be the correct type - all other properties are strings if (property.Name == "CreatedDate" && !string.IsNullOrEmpty(property.InnerText)) { node.Properties["CreatedDate"] = DateTime.Parse(property.InnerText); continue; } if (property.Name == "LastModifiedDate" && !string.IsNullOrEmpty(property.InnerText)) { node.Properties["LastModifiedDate"] = DateTime.Parse(property.InnerText); continue; } node.Properties[property.Name] = property.InnerText; } // If we didn't have a CreatedDate or LastModifiedDate then set them to now. if (node.Properties["CreatedDate"] == null) node.Properties["CreatedDate"] = DateTime.Now; if (node.Properties["LastModifiedDate"] == null) node.Properties["LastModifiedDate"] = DateTime.Now; // Save our changes to the node. node.Update(); node.MoveToLast(existingNodes); // Should already be at the end but I prefer to make sure :) XmlNodeList childNodes = newNodeXml.SelectNodes("Node"); // If we have child nodes then make a recursive call passing in the current nodes Children property as the collection to add to. if (childNodes.Count > 0) AddNodes(pubWeb, isGlobal, node.Children, childNodes); } }
/// <summary> /// Enumerates the collection. /// </summary> /// <param name="pubWeb">The publishing web.</param> /// <param name="isGlobal">if set to <c>true</c> [is global].</param> /// <param name="nodes">The nodes.</param> /// <param name="xmlParentNode">The XML parent node.</param> private static void EnumerateCollection(PublishingWeb pubWeb, bool isGlobal, SPNavigationNodeCollection nodes, XmlElement xmlParentNode) { if (nodes == null || nodes.Count == 0) return; foreach (SPNavigationNode node in nodes) { NodeTypes type = NodeTypes.None; if (node.Properties["NodeType"] != null && !string.IsNullOrEmpty(node.Properties["NodeType"].ToString())) type = (NodeTypes)Enum.Parse(typeof(NodeTypes), node.Properties["NodeType"].ToString()); if (isGlobal) { if ((type == NodeTypes.Area && !pubWeb.Navigation.GlobalIncludeSubSites) || (type == NodeTypes.Page && !pubWeb.Navigation.GlobalIncludePages)) continue; } else { if ((type == NodeTypes.Area && !pubWeb.Navigation.CurrentIncludeSubSites) || (type == NodeTypes.Page && !pubWeb.Navigation.CurrentIncludePages)) continue; } XmlElement xmlChildNode = xmlParentNode.OwnerDocument.CreateElement("Node"); xmlParentNode.AppendChild(xmlChildNode); xmlChildNode.SetAttribute("Id", node.Id.ToString()); xmlChildNode.SetAttribute("Title", node.Title); // Set the default visibility to true. xmlChildNode.SetAttribute("IsVisible", node.IsVisible.ToString()); #region Determine Visibility if (type == NodeTypes.Area) { SPWeb web = null; try { string name = node.Url.Trim('/'); if (name.Length != 0 && name.IndexOf("/") > 0) { name = name.Substring(name.LastIndexOf('/') + 1); } try { web = pubWeb.Web.Webs[name]; } catch (ArgumentException) { } if (web != null && web.Exists && web.ServerRelativeUrl.ToLower() == node.Url.ToLower() && PublishingWeb.IsPublishingWeb(web)) { PublishingWeb tempPubWeb = PublishingWeb.GetPublishingWeb(web); if (isGlobal) xmlChildNode.SetAttribute("IsVisible", tempPubWeb.IncludeInGlobalNavigation.ToString()); else xmlChildNode.SetAttribute("IsVisible", tempPubWeb.IncludeInCurrentNavigation.ToString()); } } finally { if (web != null) web.Dispose(); } } else if (type == NodeTypes.Page) { PublishingPage page = null; try { page = pubWeb.GetPublishingPages()[node.Url]; } catch (ArgumentException) { } if (page != null) { if (isGlobal) xmlChildNode.SetAttribute("IsVisible", page.IncludeInGlobalNavigation.ToString()); else xmlChildNode.SetAttribute("IsVisible", page.IncludeInCurrentNavigation.ToString()); } } #endregion XmlElement xmlProp = xmlParentNode.OwnerDocument.CreateElement("Url"); xmlProp.InnerText = node.Url; xmlChildNode.AppendChild(xmlProp); foreach (DictionaryEntry d in node.Properties) { xmlProp = xmlParentNode.OwnerDocument.CreateElement(d.Key.ToString()); xmlProp.InnerText = d.Value.ToString(); xmlChildNode.AppendChild(xmlProp); } EnumerateCollection(pubWeb, isGlobal, node.Children, xmlChildNode); } }
private void RecurseNodes(SPNavigationNodeCollection nodes) { for(int i = 0; i < nodes.Count; i++) { if ((nodes[i].Title == "Agenda Tasks") || (nodes[i].Title == "Key People")) { //Keep it } else { nodes[i].Delete(); } if (nodes[i].Children != null) RecurseNodes(nodes[i].Children); } }