//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();
        }
Ejemplo n.º 2
0
        public static SPNavigationNode AddNavigationLink(SPNavigationNode parentNode, string title, string url, string group)
        {
            var subNode = new SPNavigationNode(title, url);
            parentNode.Children.Add(subNode, parentNode);
            subNode.Properties.Add("Audience", ";;;;" + group);
            subNode.Update();
            parentNode.Update();

            return subNode;
        }
Ejemplo n.º 3
0
        public SPNavigationNode AddNavigationLink(SPNavigationNode parentNode, string title, string url, string group)
        {
            var subNode = new SPNavigationNode(title, url);

            parentNode.Children.Add(subNode, parentNode);
            subNode.Properties.Add("Audience", ";;;;" + group);
            subNode.Update();
            parentNode.Update();

            return(subNode);
        }
Ejemplo n.º 4
0
        /*
         * public SPNavigationNode AddHeading(string title, string url, string group)
         * {
         *  if (!url.Equals("javascript:void(0)"))
         *  {
         *      Uri uri = new Uri(url);
         *      return AddHeading(title, uri, group);
         *  }
         *  else
         *  {
         *      if (nodes != null)
         *      {
         *          SPNavigationNode nodeItem = SPNavigationSiteMapNode.CreateSPNavigationNode(title, url, Microsoft.SharePoint.Publishing.NodeTypes.Heading, nodes);
         *          nodeItem.Properties.Add("Audience", ";;;;" + group);
         *          nodeItem.Update();
         *
         *          return nodeItem;
         *      }
         *
         *      return null;
         *  }
         * }
         *
         * public SPNavigationNode AddHeading(string title, Uri url, string group)
         * {
         *  if (nodes != null)
         *  {
         *      SPNavigationNode nodeItem = SPNavigationSiteMapNode.CreateSPNavigationNode(title, url.ToString(), Microsoft.SharePoint.Publishing.NodeTypes.Heading, nodes);
         *      nodeItem.Properties.Add("Audience", ";;;;" + group);
         *      nodeItem.Update();
         *
         *      return nodeItem;
         *  }
         *
         *  return null;
         * }
         */
        #endregion

        public SPNavigationNode AddHeading(string title, string url, string group)
        {
            if (nodes != null)
            {
                SPNavigationNode nodeItem = SPNavigationSiteMapNode.CreateSPNavigationNode(title, url, Microsoft.SharePoint.Publishing.NodeTypes.Heading, nodes);
                nodeItem.Properties.Add("Audience", ";;;;" + group);
                nodeItem.Update();

                return(nodeItem);
            }
            return(null);
        }
Ejemplo n.º 5
0
        private void GenerateLeftMenu(SPWeb web)
        {
            var nodeCollection = web.Navigation.QuickLaunch;

            // Delete all existing items in Quick Launch
            var counter = 0;

            while (nodeCollection.Count != counter && nodeCollection.Count > 0)
            {
                counter++;
                var item = nodeCollection[0];
                item.Delete();
            }

            //nodeCollection = web.Navigation.QuickLaunch;
            var timeSheetHeading = new SPNavigationNode("Timesheet", web.Url);

            nodeCollection.AddAsLast(timeSheetHeading);
            foreach (var culture in web.SupportedUICultures)
            {
                string timeSheetResourceKey = $"$Resources:{ResourceFilename},{TimeSheet}";
                var    locStr = SPUtility.GetLocalizedString(timeSheetResourceKey, ResourceFilename,
                                                             (uint)culture.LCID);
                timeSheetHeading.TitleResource.SetValueForUICulture(culture, locStr);
            }
            timeSheetHeading.Update();

            //add child
            var leaveRequest = new SPNavigationNode(
                $"$Resources:{ResourceFilename},{LeaveRequest}",
                $"{web.Url}/_layouts/15/RBVH.Stada.Intranet.WebPages/LeaveManagement.aspx");

            timeSheetHeading.Children.AddAsLast(leaveRequest);

            var leaveApprovalTaskList = new SPNavigationNode(
                $"$Resources:{ResourceFilename},{LeaveApprovalList}",
                $"{web.Url}/_layouts/15/RBVH.Stada.Intranet.WebPages/LeaveManagementApprovalTask.aspx");

            timeSheetHeading.Children.AddAsLast(leaveApprovalTaskList);


            var myOvertimeRequest = new SPNavigationNode(
                $"$Resources:{ResourceFilename},{MyOverTime}", $"{web.Url}/_layouts/15/RBVH.Stada.Intranet.WebPages/MyOvertime.aspx");

            timeSheetHeading.Children.AddAsLast(myOvertimeRequest);

            var overtimeRequest = new SPNavigationNode(
                $"$Resources:{ResourceFilename},{OvertimeRequest}", $"{web.Url}/SitePages/OvertimeManagement.aspx");

            timeSheetHeading.Children.AddAsLast(overtimeRequest);

            var overtimeApprovalList = new SPNavigationNode(
                $"$Resources:{ResourceFilename},{OvertimeApprovallist}", $"{web.Url}/SitePages/OvertimeApprovalList.aspx");

            timeSheetHeading.Children.AddAsLast(overtimeApprovalList);

            var myshiftRequest =
                new SPNavigationNode($"$Resources:{ResourceFilename},{MyShiftRequest}",
                                     $"{web.Url}/_layouts/15/RBVH.Stada.Intranet.WebPages/MyShiftTime.aspx");

            timeSheetHeading.Children.AddAsLast(myshiftRequest);

            var shiftRequest =
                new SPNavigationNode($"$Resources:{ResourceFilename},{ShiftRequest}",
                                     $"{web.Url}/SitePages/ShiftManagement.aspx");

            timeSheetHeading.Children.AddAsLast(shiftRequest);

            var shiftApprovalList = new SPNavigationNode(
                $"$Resources:{ResourceFilename},{ShiftApprovallist}", $"{web.Url}/SitePages/ShiftApprovalList.aspx");

            timeSheetHeading.Children.AddAsLast(shiftApprovalList);

            var changeShiftRequest =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{ChangeShiftRequest}", $"{web.Url}/SitePages/ChangeShiftManagement.aspx");

            timeSheetHeading.Children.AddAsLast(changeShiftRequest);
            var changeShiftRequestTaskList =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{ChangeShiftRequestTaskList}", $"{web.Url}/SitePages/ChangeShiftManagementTaskList.aspx");

            timeSheetHeading.Children.AddAsLast(changeShiftRequestTaskList);

            var requestToNotOvertime =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{RequestToNotOvertime}", $"{web.Url}/SitePages/LeaveOfAbsenceManagement.aspx");

            timeSheetHeading.Children.AddAsLast(requestToNotOvertime);
            var requestToNotOvertimeTaskList =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{RequestToNotOvertimeTaskList}", $"{web.Url}/SitePages/LeaveOfAbsenceManagementTaskList.aspx");

            timeSheetHeading.Children.AddAsLast(requestToNotOvertimeTaskList);

            var transportationRequest =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{TransportationRequest}", $"{web.Url}/SitePages/TransportationManagement.aspx");

            timeSheetHeading.Children.AddAsLast(transportationRequest);

            var transportationTaskList =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{TransportTaskList}", $"{web.Url}/SitePages/TransportationManagementTaskList.aspx");

            timeSheetHeading.Children.AddAsLast(transportationTaskList);

            timeSheetHeading.Update();

            var supplierMeeting =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{SupplierMeetingRequest}",
                    web.Url);

            nodeCollection.AddAsLast(supplierMeeting);

            var stationaryRequestHeading =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{StationaryRequest}", web.Url);

            nodeCollection.AddAsLast(stationaryRequestHeading);

            var registerForTransportationHeading =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{RegisterForTransportation}",
                    web.Url);

            nodeCollection.AddAsLast(registerForTransportationHeading);

            var requestFormHeading =
                new SPNavigationNode($"$Resources:{ResourceFilename},{RequestForm}",
                                     web.Url);

            nodeCollection.AddAsLast(requestFormHeading);

            var guessWelcomingRequestHeading =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{GuessWelcomingRequest}", web.Url);

            nodeCollection.AddAsLast(guessWelcomingRequestHeading);

            var informationUpdateRequestHeading =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{InformationUpdateRequest}",
                    web.Url);

            nodeCollection.AddAsLast(informationUpdateRequestHeading);

            var requisitionOfDocumentsHeading =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{RequisitionOfDocuments}",
                    web.Url);

            nodeCollection.AddAsLast(requisitionOfDocumentsHeading);

            var diplomaSupplementRequestHeading =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{DiplomaSupplementRequest}",
                    web.Url);

            nodeCollection.AddAsLast(diplomaSupplementRequestHeading);

            var recruitmentRequestHeading =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{RecruitmentRequest}", web.Url);

            nodeCollection.AddAsLast(recruitmentRequestHeading);

            var businessTripHeading =
                new SPNavigationNode($"$Resources:{ResourceFilename},{BusinessTrip}",
                                     web.Url);

            nodeCollection.AddAsLast(businessTripHeading);

            var licenseToTransportHeading =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{LicenseToTransport}", web.Url);

            nodeCollection.AddAsLast(licenseToTransportHeading);

            var meetingRoomHeading =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{MeetingRoomBooking}", web.Url);

            nodeCollection.AddAsLast(meetingRoomHeading);

            var employeeShiftTime =
                new SPNavigationNode("Employee Shift Time", web.Url);

            nodeCollection.AddAsLast(employeeShiftTime);
            // Update title resource
            foreach (var culture in web.SupportedUICultures)
            {
                var timeSheetResourceKey = $"$Resources:{ResourceFilename},{EmployeeShiftTime}";
                var locStr = SPUtility.GetLocalizedString(timeSheetResourceKey, ResourceFilename,
                                                          (uint)culture.LCID);
                employeeShiftTime.TitleResource.SetValueForUICulture(culture, locStr);
            }
            employeeShiftTime.Update();

            var rAndDHeading = new SPNavigationNode("R&D", web.Url);

            nodeCollection.AddAsLast(rAndDHeading);
            // Update title resource
            foreach (var culture in web.SupportedUICultures)
            {
                var timeSheetResourceKey = $"$Resources:{ResourceFilename},{RAndD}";
                var locStr = SPUtility.GetLocalizedString(timeSheetResourceKey, ResourceFilename,
                                                          (uint)culture.LCID);
                rAndDHeading.TitleResource.SetValueForUICulture(culture, locStr);
            }
            rAndDHeading.Update();

            //Add child
            var dissoierForExportingRequest =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{DissoierForExportingRequest}",
                    web.Url);

            rAndDHeading.Children.AddAsLast(dissoierForExportingRequest);
            var dissoierForDomesticRequest =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{DissoierForDomesticRequest}",
                    web.Url);

            rAndDHeading.Children.AddAsLast(dissoierForDomesticRequest);
            var notConfirmingRequest =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{NotconformingRequest}", web.Url);

            rAndDHeading.Children.AddAsLast(notConfirmingRequest);
            var designRequest =
                new SPNavigationNode(
                    $"$Resources:{ResourceFilename},{DesignRequest}", web.Url);

            rAndDHeading.Children.AddAsLast(designRequest);
            rAndDHeading.Update();
        }
Ejemplo n.º 6
0
 public void Update()
 {
     m_navigationNode.Update();
 }
        /// <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);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Processes the top nav nodes.
        /// </summary>
        /// <param name="web">The web.</param>
        /// <param name="title">The title.</param>
        /// <param name="url">The URL.</param>
        /// <param name="parentUrl">The parent URL.</param>
        public static void ProcessTopNavNodes(SPWeb web, string title, string url, string parentUrl)
        {
            if (parentUrl == "/")
            {
                return;
            }
            web.Navigation.UseShared = true;
            SPNavigationNode parentNode = web.Navigation.GetNodeByUrl(parentUrl);
            SPNavigationNode node = new SPNavigationNode(title, url);

            parentNode.Children.AddAsLast(node);
            node.Update();
        }