Пример #1
0
        /// <summary>
        /// Add a node to quickLaunch or top navigation bar
        /// </summary>
        /// <param name="web">Site to be processed - can be root web or sub site</param>
        /// <param name="nodeTitle">the title of node to add</param>
        /// <param name="nodeUri">the url of node to add</param>
        /// <param name="parentNodeTitle">if string.Empty, then will add this node as top level node</param>
        /// <param name="isQucikLaunch">true: add to quickLaunch; otherwise, add to top navigation bar</param>
        public static void AddNavigationNode(this Web web, string nodeTitle, Uri nodeUri, string parentNodeTitle, bool isQuickLaunch)
        {
            web.Context.Load(web, w => w.Navigation.QuickLaunch, w => w.Navigation.TopNavigationBar);
            web.Context.ExecuteQuery();
            NavigationNodeCreationInformation node = new NavigationNodeCreationInformation();
            node.AsLastNode = true;
            node.Title = nodeTitle;
            node.Url = nodeUri != null ? nodeUri.OriginalString : "";

            if (isQuickLaunch)
            {
                var quickLaunch = web.Navigation.QuickLaunch;
                if (string.IsNullOrEmpty(parentNodeTitle))
                {
                    quickLaunch.Add(node);
                }
                else
                {
                    foreach (var nodeInfo in quickLaunch)
                    {
                        if (nodeInfo.Title == parentNodeTitle)
                        {
                            nodeInfo.Children.Add(node);
                            break;
                        }
                    }
                }
            }
            else
            {
                var topLink = web.Navigation.TopNavigationBar;
                topLink.Add(node);
            }
            web.Context.ExecuteQuery();
        }
Пример #2
0
 public static bool CreateDocumentLibrary(string libraryName)
 {
     using (ClientContext clientContext = GetContextObject())
     {
         Web web = clientContext.Web;
         clientContext.Load(web, website => website.ServerRelativeUrl);
         clientContext.ExecuteQuery();
         Regex  regex               = new Regex(Configuration.SiteUrl, RegexOptions.IgnoreCase);
         string documentLibrary     = regex.Replace(Configuration.FileUrl, string.Empty);
         ListCreationInformation cr = new ListCreationInformation();
         cr.Title             = libraryName;
         cr.TemplateType      = 101;
         cr.QuickLaunchOption = QuickLaunchOptions.On;
         var dlAdd = web.Lists.Add(cr);
         web.QuickLaunchEnabled = true;
         web.Update();
         clientContext.Load(dlAdd);
         clientContext.ExecuteQuery();
         NavigationNodeCreationInformation nr = new NavigationNodeCreationInformation();
         nr.Title      = libraryName;
         nr.AsLastNode = true;
         nr.Url        = Configuration.SiteUrl + libraryName + "/Forms/AllItems.aspx";
         var dlAdd1 = web.Navigation.QuickLaunch.Add(nr);
         web.QuickLaunchEnabled = true;
         web.Update();
         clientContext.Load(dlAdd1);
         clientContext.ExecuteQuery();
     }
     return(true);
 }
Пример #3
0
        public override void AddNavigationNode(string title, string url, NavigationNodeLocation location)
        {
            NavigationNodeCreationInformation newNavNode = new NavigationNodeCreationInformation();

            newNavNode.Title = title;
            newNavNode.Url   = url;

            NavigationNodeCollection navNodeColl = null;

            switch (location)
            {
            case NavigationNodeLocation.TopNavigationBar:
                navNodeColl = _web.Navigation.TopNavigationBar;
                break;

            case NavigationNodeLocation.QuickLaunchLists:
                navNodeColl = _web.Navigation.QuickLaunch;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(location), location, null);
            }


            try
            {
                navNodeColl.Add(newNavNode);
                _context.ExecuteQuery();
            }
            catch (Exception)
            {
                //ignore, already exists
            }
        }
 public void CreateTopNavNode(string NodeTitle, string NodeUrl, bool ExternalNode)
 {
     NavigationNodeCreationInformation newNode = new NavigationNodeCreationInformation();
       newNode.IsExternal = ExternalNode;
       newNode.Title = NodeTitle;
       newNode.Url = sitePages.RootFolder.ServerRelativeUrl + "/" + NodeUrl;
       newNode.AsLastNode = true;
       topNavNodes.Add(newNode);
       clientContext.ExecuteQuery();
 }
Пример #5
0
        static NavigationNode CreateTopNavNode(string NodeTitle, string NodeUrl, bool ExternalNode)
        {
            NavigationNodeCreationInformation newNode = new NavigationNodeCreationInformation();

            newNode.IsExternal = ExternalNode;
            newNode.Title      = NodeTitle;
            newNode.Url        = NodeUrl;
            newNode.AsLastNode = true;
            return(TopNavNodes.Add(newNode));
        }
Пример #6
0
 static void AddHomeTopNavNode()
 {
     NavigationNodeCreationInformation newNode = new NavigationNodeCreationInformation();
       newNode.IsExternal = false;
       newNode.Title = "Home";
       newNode.Url = site.Url;
       newNode.AsLastNode = true;
       TopNavNodes.Add(newNode);
       clientContext.ExecuteQuery();
 }
Пример #7
0
        /// <summary>
        /// Add a node to quick launch, top navigation bar or search navigation. The node will be added as the last node in the
        /// collection.
        /// </summary>
        /// <param name="web">Site to be processed - can be root web or sub site</param>
        /// <param name="nodeTitle">the title of node to add</param>
        /// <param name="nodeUri">the url of node to add</param>
        /// <param name="parentNodeTitle">if string.Empty, then will add this node as top level node</param>
        /// <param name="navigationType">the type of navigation, quick launch, top navigation or search navigation</param>
        /// <param name="isExternal">true if the link is an external link</param>
        /// <param name="asLastNode">true if the link should be added as the last node of the collection</param>

        public static void AddNavigationNode(this Web web, string nodeTitle, Uri nodeUri, string parentNodeTitle, NavigationType navigationType, bool isExternal = false, bool asLastNode = true)
        {
            web.Context.Load(web, w => w.Navigation.QuickLaunch, w => w.Navigation.TopNavigationBar);
            web.Context.ExecuteQueryRetry();
            NavigationNodeCreationInformation node = new NavigationNodeCreationInformation
            {
                AsLastNode = asLastNode,
                Title      = nodeTitle,
                Url        = nodeUri != null ? nodeUri.OriginalString : string.Empty,
                IsExternal = isExternal
            };

            try
            {
                if (navigationType == NavigationType.QuickLaunch)
                {
                    var quickLaunch = web.Navigation.QuickLaunch;
                    if (string.IsNullOrEmpty(parentNodeTitle))
                    {
                        quickLaunch.Add(node);
                        return;
                    }
                    NavigationNode parentNode = quickLaunch.SingleOrDefault(n => n.Title == parentNodeTitle);
                    if (parentNode != null)
                    {
                        parentNode.Children.Add(node);
                    }
                }
                else if (navigationType == NavigationType.TopNavigationBar)
                {
                    var topLink = web.Navigation.TopNavigationBar;
                    if (!string.IsNullOrEmpty(parentNodeTitle))
                    {
                        var parentNode = topLink.FirstOrDefault(n => n.Title == parentNodeTitle);
                        if (parentNode != null)
                        {
                            parentNode.Children.Add(node);
                        }
                    }
                    else
                    {
                        topLink.Add(node);
                    }
                }
                else if (navigationType == NavigationType.SearchNav)
                {
                    var searchNavigation = web.LoadSearchNavigation();
                    searchNavigation.Add(node);
                }
            }
            finally
            {
                web.Context.ExecuteQueryRetry();
            }
        }
Пример #8
0
        static void AddHomeTopNavNode()
        {
            NavigationNodeCreationInformation newNode = new NavigationNodeCreationInformation();

            newNode.IsExternal = false;
            newNode.Title      = "Home";
            newNode.Url        = site.Url;
            newNode.AsLastNode = true;
            TopNavNodes.Add(newNode);
            clientContext.ExecuteQuery();
        }
Пример #9
0
        public void CreateTopNavNode(string NodeTitle, string NodeUrl, bool ExternalNode)
        {
            NavigationNodeCreationInformation newNode = new NavigationNodeCreationInformation();

            newNode.IsExternal = ExternalNode;
            newNode.Title      = NodeTitle;
            newNode.Url        = sitePages.RootFolder.ServerRelativeUrl + "/" + NodeUrl;
            newNode.AsLastNode = true;
            topNavNodes.Add(newNode);
            clientContext.ExecuteQuery();
        }
Пример #10
0
        static void CreateTopNavNode(string title, string path)
        {
            string nodeUrl = site.Url + path;
            NavigationNodeCreationInformation newNode = new NavigationNodeCreationInformation();

            newNode.IsExternal = false;
            newNode.Title      = title;
            newNode.Url        = nodeUrl;
            newNode.AsLastNode = true;
            TopNavNodes.Add(newNode);
            clientContext.ExecuteQuery();
        }
Пример #11
0
        /// <summary>
        /// Add a node to quick launch, top navigation bar or search navigation. The node will be added as the last node in the
        /// collection.
        /// </summary>
        /// <param name="web">Site to be processed - can be root web or sub site</param>
        /// <param name="nodeTitle">the title of node to add</param>
        /// <param name="nodeUri">the URL of node to add</param>
        /// <param name="parentNodeTitle">if string.Empty, then will add this node as top level node. Contains the title of the immediate parent node, for third level nodes, providing <paramref name="l1ParentNodeTitle"/> is required.</param>
        /// <param name="navigationType">the type of navigation, quick launch, top navigation or search navigation</param>
        /// <param name="isExternal">true if the link is an external link</param>
        /// <param name="asLastNode">true if the link should be added as the last node of the collection</param>
        /// <param name="l1ParentNodeTitle">title of the first level parent, if this node is a third level navigation node</param>
        /// <returns>Newly added NavigationNode</returns>
        public static NavigationNode AddNavigationNode(this Web web, string nodeTitle, Uri nodeUri, string parentNodeTitle, NavigationType navigationType, bool isExternal = false, bool asLastNode = true, string l1ParentNodeTitle = null)
        {
            web.Context.Load(web, w => w.Navigation.QuickLaunch, w => w.Navigation.TopNavigationBar);
            web.Context.ExecuteQueryRetry();
            var node = new NavigationNodeCreationInformation
            {
                AsLastNode = asLastNode,
                Title      = nodeTitle,
                Url        = nodeUri != null ? nodeUri.OriginalString : string.Empty,
                IsExternal = isExternal
            };

            NavigationNode navigationNode = null;

            try
            {
                if (navigationType == NavigationType.QuickLaunch)
                {
                    var quickLaunch = web.Navigation.QuickLaunch;
                    if (string.IsNullOrEmpty(parentNodeTitle))
                    {
                        navigationNode = quickLaunch.Add(node);
                    }
                    else
                    {
                        navigationNode = CreateNodeAsChild(web, quickLaunch, node, parentNodeTitle, l1ParentNodeTitle);
                    }
                }
                else if (navigationType == NavigationType.TopNavigationBar)
                {
                    var topLink = web.Navigation.TopNavigationBar;
                    if (!string.IsNullOrEmpty(parentNodeTitle))
                    {
                        navigationNode = CreateNodeAsChild(web, topLink, node, parentNodeTitle, l1ParentNodeTitle);
                    }
                    else
                    {
                        navigationNode = topLink.Add(node);
                    }
                }
                else if (navigationType == NavigationType.SearchNav)
                {
                    var searchNavigation = web.LoadSearchNavigation();
                    navigationNode = searchNavigation.Add(node);
                }
            }
            finally
            {
                web.Context.ExecuteQueryRetry();
            }
            return(navigationNode);
        }
Пример #12
0
        public static void AddPageToNavigation(this Web value, ClientContext ctx, string pageUrl)
        {
            var quickLaunch = value.Navigation.QuickLaunch;
            var docIndex    = new NavigationNodeCreationInformation
            {
                Title      = "Document Index",
                Url        = pageUrl,
                AsLastNode = true
            };

            quickLaunch.Add(docIndex);
            ctx.Load(quickLaunch);
            ctx.ExecuteQuery();
        }
Пример #13
0
        private void AddNode(NavigationNodeCreator node, NavigationNodeCollection navigationNodes)
        {
            var found = false;

            foreach (var existingNode in navigationNodes)
            {
                if (node.Title == existingNode.Title)
                {
                    found = true;
                    if (node.Children != null && node.Children.Count > 0)
                    {
                        _ctx.Load(existingNode, n => n.Children.Include(c => c.Title));
                        _ctx.ExecuteQueryRetry();
                        foreach (var childNode in node.Children)
                        {
                            AddNode(childNode, existingNode.Children);
                        }
                    }
                    break;
                }
            }
            if (!found)
            {
                var creator = new NavigationNodeCreationInformation
                {
                    Title      = node.Title,
                    IsExternal = node.IsExternal,
                    Url        =
                        node.IsExternal
                            ? node.Url.Replace("{@WebUrl}", _web.Url).Replace("{@WebServerRelativeUrl}", _web.ServerRelativeUrl)
                            : GetUrl(node.Url)
                };
                if (node.AsLastNode)
                {
                    creator.AsLastNode = true;
                }
                var newNode = navigationNodes.Add(creator);

                if (node.Children != null && node.Children.Count > 0)
                {
                    _ctx.Load(newNode, n => n.Children.Include(c => c.Title));
                    _ctx.ExecuteQueryRetry();
                    foreach (var childNode in node.Children)
                    {
                        AddNode(childNode, newNode.Children);
                    }
                }
            }
        }
Пример #14
0
        public static void AddGoogleToNav(ClientContext ctx)
        {
            Web web = ctx.Web;
            NavigationNodeCollection QuickLanchcoll = web.Navigation.QuickLaunch;
            //ctx.Load(QuickLanchcoll);
            //ctx.ExecuteQuery();

            NavigationNodeCreationInformation NewNode = new NavigationNodeCreationInformation();

            NewNode.Title = "Google";
            NewNode.Url   = "https://google.com";

            QuickLanchcoll.Add(NewNode);
            //ctx.Load(QuickLanchcoll);
            ctx.ExecuteQuery();
        }
Пример #15
0
        public static void AddQuickLaunch(NavigationNodeCollection quickLaunch, string Title, string Url, bool isChildNode = false)
        {
            NavigationNodeCreationInformation navci = new NavigationNodeCreationInformation();

            navci.AsLastNode = true;
            navci.Title      = Title;
            navci.Url        = Url;
            if (!isChildNode)
            {
                quickLaunch.Add(navci);
            }
            else
            {
                quickLaunch[quickLaunch.Count - 1].Children.Add(navci);
            }
        }
Пример #16
0
        /// <summary>
        /// Handler for the navigation note configurations
        /// </summary>
        /// <param name="clientContext">
        /// Context to apply navigation nodes to
        /// </param>
        /// <param name="siteTemplate">
        /// XML structure for template
        /// </param>
        private void DeployNavigation(ClientContext clientContext, XElement siteTemplate)
        {
            XElement navigationNodesToCreate = siteTemplate.Element("NavigationNodes");

            if (navigationNodesToCreate != null)
            {
                Web web = clientContext.Web;
                clientContext.Load(web);
                clientContext.ExecuteQuery();
                foreach (XElement navigationNodeToCreate in navigationNodesToCreate.Elements())
                {
                    string title   = navigationNodeToCreate.Attribute("Title").Value;
                    string url     = navigationNodeToCreate.Attribute("Url").Value;
                    string navType = navigationNodeToCreate.Attribute("Type").Value;

                    if (url.StartsWith("/"))
                    {
                        url = URLCombine(web.Url, url);
                    }

                    // Let's create the nodes based on configuration to quick launch
                    NavigationNodeCreationInformation nodeInformation = new NavigationNodeCreationInformation
                    {
                        Title = title,
                        Url   = url
                    };

                    clientContext.Load(web.Navigation.QuickLaunch);
                    clientContext.ExecuteQuery();

                    if (navType == "TopNavBar")
                    {
                        web.Navigation.TopNavigationBar.Add(nodeInformation);
                    }
                    else
                    {
                        web.Navigation.QuickLaunch.Add(nodeInformation);
                    }

                    clientContext.ExecuteQuery();
                }
            }
        }
Пример #17
0
        /// <summary>
        /// Add a node to quick launch, top navigation bar or search navigation. The node will be added as the last node in the
        /// collection.
        /// </summary>
        /// <param name="web">Site to be processed - can be root web or sub site</param>
        /// <param name="nodeTitle">the title of node to add</param>
        /// <param name="nodeUri">the url of node to add</param>
        /// <param name="parentNodeTitle">if string.Empty, then will add this node as top level node</param>
        /// <param name="navigationType">the type of navigation, quick launch, top navigation or search navigation</param>
        public static void AddNavigationNode(this Web web, string nodeTitle, Uri nodeUri, string parentNodeTitle, NavigationType navigationType)
        {
            web.Context.Load(web, w => w.Navigation.QuickLaunch, w => w.Navigation.TopNavigationBar);
            web.Context.ExecuteQueryRetry();
            NavigationNodeCreationInformation node = new NavigationNodeCreationInformation
            {
                AsLastNode = true,
                Title = nodeTitle,
                Url = nodeUri != null ? nodeUri.OriginalString : string.Empty
            };

            try
            {
                if (navigationType == NavigationType.QuickLaunch)
                {
                    var quickLaunch = web.Navigation.QuickLaunch;
                    if (string.IsNullOrEmpty(parentNodeTitle))
                    {
                        quickLaunch.Add(node);
                        return;
                    }
                    NavigationNode parentNode = quickLaunch.SingleOrDefault(n => n.Title == parentNodeTitle);
                    if (parentNode != null)
                    {
                        parentNode.Children.Add(node);
                    }
                }
                else if (navigationType == NavigationType.TopNavigationBar)
                {
                    var topLink = web.Navigation.TopNavigationBar;
                    topLink.Add(node);
                }
                else if (navigationType == NavigationType.SearchNav)
                {
                    var searchNavigation = web.LoadSearchNavigation();
                    searchNavigation.Add(node);
                }
            }
            finally
            {
                web.Context.ExecuteQueryRetry();
            }
        }
        public async Task AddNode_GeneratesCorrectRequest()
        {
            // ARRANGE
            var mockNewNodeRequest = new NavigationNodeCreationInformation()
            {
                Title = "mockTitle",
                Url   = new Uri("https://mocksite.com")
            };
            var expectedUri     = new Uri($"{mockWebUrl}/_api/web/navigation/quicklaunch");
            var expectedContent = "{\"Title\":\"mockTitle\",\"Url\":\"https://mocksite.com\"}";

            using (var response = new HttpResponseMessage())
                using (var gsc = GraphServiceTestClient.Create(response))
                {
                    // ACT
                    await gsc.GraphServiceClient
                    .SharePointAPI(mockWebUrl)
                    .Web
                    .Navigation
                    .QuickLaunch
                    .Request()
                    .AddAsync(mockNewNodeRequest);

                    var actualContent = gsc.HttpProvider.ContentAsString;

                    // ASSERT
                    gsc.HttpProvider.Verify(
                        provider => provider.SendAsync(
                            It.Is <HttpRequestMessage>(req =>
                                                       req.Method == HttpMethod.Post &&
                                                       req.RequestUri == expectedUri &&
                                                       req.Headers.Authorization != null
                                                       ),
                            It.IsAny <HttpCompletionOption>(),
                            It.IsAny <CancellationToken>()
                            ),
                        Times.Exactly(1)
                        );
                    Assert.Equal(Microsoft.Graph.CoreConstants.MimeTypeNames.Application.Json, gsc.HttpProvider.ContentHeaders.ContentType.MediaType);
                    Assert.Equal(expectedContent, actualContent);
                }
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="clientContext"></param>
        /// <param name="web">Web which is already initiated</param>
        /// <param name="siteTemplate"></param>
        private void DeployNavigation(ClientContext clientContext, Web web, XElement siteTemplate)
        {
            XElement navigationNodesToCreate = siteTemplate.Element("NavigationNodes");

            if (navigationNodesToCreate != null)
            {
                foreach (XElement navigationNodeToCreate in navigationNodesToCreate.Elements())
                {
                    // Let's create the nodes based on configuration to quick launch
                    NavigationNodeCreationInformation nodeInformation = new NavigationNodeCreationInformation();
                    nodeInformation.Title = navigationNodeToCreate.Attribute("Title").Value;
                    nodeInformation.Url   = navigationNodeToCreate.Attribute("Url").Value;

                    clientContext.Load(web.Navigation.QuickLaunch);
                    clientContext.ExecuteQuery();
                    web.Navigation.QuickLaunch.Add(nodeInformation);

                    clientContext.ExecuteQuery();
                }
            }
        }
        public async Task AddNode_MissingProperties_Throws(string title, string url)
        {
            var mockNewNodeRequest = new NavigationNodeCreationInformation()
            {
                Title = title,
                Url   = string.IsNullOrEmpty(url) ? null : new Uri(url)
            };

            using (var response = new HttpResponseMessage())
                using (var gsc = GraphServiceTestClient.Create(response))
                {
                    await Assert.ThrowsAsync <ArgumentException>(
                        async() => await gsc.GraphServiceClient
                        .SharePointAPI(mockWebUrl)
                        .Web
                        .Navigation
                        .QuickLaunch
                        .Request()
                        .AddAsync(mockNewNodeRequest)
                        );
                }
        }
Пример #21
0
        /// <summary>
        /// Add a node to quickLaunch or top navigation bar
        /// </summary>
        /// <param name="web">Site to be processed - can be root web or sub site</param>
        /// <param name="nodeTitle">the title of node to add</param>
        /// <param name="nodeUri">the url of node to add</param>
        /// <param name="parentNodeTitle">if string.Empty, then will add this node as top level node</param>
        /// <param name="isQuickLaunch">true: add to quickLaunch; otherwise, add to top navigation bar</param>
        public static void AddNavigationNode(this Web web, string nodeTitle, Uri nodeUri, string parentNodeTitle, bool isQuickLaunch)
        {
            web.Context.Load(web, w => w.Navigation.QuickLaunch, w => w.Navigation.TopNavigationBar);
            web.Context.ExecuteQueryRetry();
            NavigationNodeCreationInformation node = new NavigationNodeCreationInformation();

            node.AsLastNode = true;
            node.Title      = nodeTitle;
            node.Url        = nodeUri != null ? nodeUri.OriginalString : "";

            if (isQuickLaunch)
            {
                var quickLaunch = web.Navigation.QuickLaunch;
                if (string.IsNullOrEmpty(parentNodeTitle))
                {
                    quickLaunch.Add(node);
                }
                else
                {
                    foreach (var nodeInfo in quickLaunch)
                    {
                        if (nodeInfo.Title == parentNodeTitle)
                        {
                            nodeInfo.Children.Add(node);
                            break;
                        }
                    }
                }
            }
            else
            {
                var topLink = web.Navigation.TopNavigationBar;
                topLink.Add(node);
            }
            web.Context.ExecuteQueryRetry();
        }
Пример #22
0
 public static void AddNavigationLink(Web web, NavigationNodeType nodeType, string title, string url, bool asLast, string header, string previous, ClientContext clientContext)
 {
     var nodes = (nodeType == NavigationNodeType.QuickLaunch) ? web.Navigation.QuickLaunch : web.Navigation.TopNavigationBar;
     clientContext.Load(nodes, n => n.IncludeWithDefaultProperties(c => c.Children));
     clientContext.ExecuteQuery();
     if (header != null)
     {
         var headerNode = nodes.Where(x => x.Title == header).FirstOrDefault();
         if (headerNode != null)
         {
             NavigationNodeCreationInformation ciNode = new NavigationNodeCreationInformation();
             if (previous != null)
             {
                 var children = headerNode.Children;
                 clientContext.Load(children, n => n.IncludeWithDefaultProperties(c => c.Title));
                 var previousNode = children.Where(x => x.Title == previous).FirstOrDefault();
                 if (previousNode != null)
                 {
                     ciNode.PreviousNode = previousNode;
                 }
                 else
                 {
                     throw new Exception("Previous Node with title " + previous + " not found.");
                 }
             }
             ciNode.AsLastNode = asLast;
             ciNode.Title = title;
             ciNode.Url = url;
             NavigationNode node = headerNode.Children.Add(ciNode);
             clientContext.ExecuteQuery();
         }
         else
         {
             throw new Exception("Header Node with title " + header + " not found");
         }
     }
     else
     {
         NavigationNodeCreationInformation ciNode = new NavigationNodeCreationInformation();
         ciNode.AsLastNode = asLast;
         ciNode.Title = title;
         ciNode.Url = url;
         NavigationNode node = nodes.Add(ciNode);
         clientContext.ExecuteQuery();
     }
 }
        protected void Button1_Click(object sender, EventArgs e)
        {
            //List<string> _urlList = new List<string>();
            //_urlList.Add("http://sp2010app/subsite1");
            //_urlList.Add("http://sp2010app/subsite2");
            //_urlList.Add("http://sp2010app/subsite3");
            //_urlList.Add("http://sp2010app/subsite4");
            //_urlList.Add("http://sp2010app/subsite5");
            //_urlList.Add("http://sp2010app/subsite6");



            string filePath       = "";
            string login          = "******";
            string password       = "******";
            var    securepassword = new SecureString();

            foreach (char c in password)
            {
                securepassword.AppendChar(c);
            }

            string siteUrl = "https://verinontechnology.sharepoint.com/sites/AppPractice/";

            ClientContext context           = new ClientContext(siteUrl);
            var           onlineCredentials = new SharePointOnlineCredentials(login, securepassword);

            context.Credentials = onlineCredentials;
            Web web = context.Web;

            context.ExecuteQuery();

            //NavigationNodeCreationInformation navCreation = new NavigationNodeCreationInformation();
            //navCreation.Title = "SiteCollection";
            //navCreation.Url = "https://verinontechnology.sharepoint.com/sites/AppPractice/";
            //NavigationNode quickluncnode = context.Web.Navigation.QuickLaunch.Add(navCreation);
            //context.Load(quickluncnode);
            //context.ExecuteQuery();

            //NavigationNodeCollection navColl=


            NavigationNodeCollection quickLaunchColl = web.Navigation.QuickLaunch;

            context.Load(quickLaunchColl);
            context.ExecuteQuery();
            NavigationNodeCollection nodes;

            foreach (NavigationNode node in quickLaunchColl)
            {
                Console.WriteLine(node.Title);
                if (node.Title == "SiteCollection Node")
                {
                    nodes = node.Children;
                    NavigationNodeCreationInformation nodeCreation = new NavigationNodeCreationInformation();
                    nodeCreation.Title = "democs link";
                    nodeCreation.Url   = "http://sps2k13sp";
                    //// Add the new navigation node to the collection
                    nodes.Add(nodeCreation);
                    context.Load(nodes);
                    context.ExecuteQuery();
                }
            }



            //foreach (SPNavigationNode node in currentNavNodes)
            //{
            //    HideNodes(node, _urlList, ospSite.Url);
            //    if (node.Children.Count > 0)
            //    {
            //        foreach (SPNavigationNode childNode in node.Children)
            //        {
            //            HideNodes(node, _urlList, ospSite.Url);
            //        }
            //    }
            //}
        }
Пример #24
0
 static NavigationNode CreateTopNavNode(string NodeTitle, string NodeUrl, bool ExternalNode) {
   NavigationNodeCreationInformation newNode = new NavigationNodeCreationInformation();
   newNode.IsExternal = ExternalNode;
   newNode.Title = NodeTitle;
   newNode.Url = NodeUrl;
   newNode.AsLastNode = true;
   return TopNavNodes.Add(newNode);
 }
Пример #25
0
        static string SetupQuotSite(string title, string customer, int id, ClientContext cc)
        {
            //SetupQuotSite(quotNum, pCName, item.Id);
            Web _w = cc.Web;

            cc.Load(_w);
            cc.ExecuteQuery();


            Web newWeb = _w.CreateWeb(title, "qoutation-" + title + "-u" + DateTime.Now.Ticks, "", "STS#0", 1033, true, false);

            cc.Load(newWeb, t => t.Title, r => r.RootFolder, wp => wp.RootFolder.WelcomePage, u => u.Url, g => g.AssociatedOwnerGroup);
            cc.ExecuteQueryRetry();
            ListCreationInformation lci = new ListCreationInformation();

            lci.Description       = "";
            lci.Title             = title + " - " + customer + " Documents";
            lci.TemplateType      = 101;
            lci.QuickLaunchOption = QuickLaunchOptions.On;
            List newLib = newWeb.Lists.Add(lci);

            cc.Load(newLib, x => x.DefaultViewUrl);
            cc.ExecuteQuery();

            CreateQuotFolders(cc, newLib, newWeb);

            NavigationNodeCollection collQuickLaunchNode = newWeb.Navigation.QuickLaunch;

            NavigationNodeCreationInformation nn0 = new NavigationNodeCreationInformation();

            nn0.Title      = "Quotation Documents";
            nn0.IsExternal = true;
            nn0.Url        = newLib.DefaultViewUrl;
            nn0.AsLastNode = true;
            collQuickLaunchNode.Add(nn0);

            NavigationNodeCreationInformation nn = new NavigationNodeCreationInformation();

            nn.Title      = "Edit Quotation";
            nn.IsExternal = true;
            nn.Url        = "/sites/quotations/Lists/Quotation Log/EditQuot.aspx?ID=" + id + "&Source=" + System.Net.WebUtility.UrlEncode(newLib.DefaultViewUrl);
            nn.AsLastNode = true;
            collQuickLaunchNode.Add(nn);

            ///
            NavigationNodeCreationInformation nn2 = new NavigationNodeCreationInformation();

            nn2.Title      = "All Quotations";
            nn2.IsExternal = true;
            nn2.Url        = "/sites/quotations/Lists/Quotation Log/AllItems.aspx";
            nn2.AsLastNode = true;
            collQuickLaunchNode.Add(nn2);


            //QuotSubmit&Mode=Site
            ///
            NavigationNodeCreationInformation nn3 = new NavigationNodeCreationInformation();

            nn3.Title      = "Release to Site";
            nn3.IsExternal = true;
            nn3.Url        = "/sites/quotations/Lists/Quotation Log/QuotSubmit.aspx?ID=" + id + "&Source=" + System.Net.WebUtility.UrlEncode(newLib.DefaultViewUrl) + "&Mode=Site";
            nn3.AsLastNode = true;
            collQuickLaunchNode.Add(nn3);

            //QuotSubmit&Mode=KAM
            ///
            NavigationNodeCreationInformation nn4 = new NavigationNodeCreationInformation();

            nn4.Title      = "Release to KAM";
            nn4.IsExternal = true;
            nn4.Url        = "/sites/quotations/Lists/Quotation Log/QuotSubmit.aspx?ID=" + id + "&Source=" + System.Net.WebUtility.UrlEncode(newLib.DefaultViewUrl) + "&Mode=KAM";
            nn4.AsLastNode = true;
            collQuickLaunchNode.Add(nn4);


            ///


            NavigationNodeCreationInformation nn5 = new NavigationNodeCreationInformation();

            nn5.Title      = "Convert to Customer Project";
            nn5.IsExternal = true;
            nn5.Url        = "https://foo.bar=" + System.Net.WebUtility.UrlEncode(newLib.DefaultViewUrl);
            nn5.AsLastNode = true;
            collQuickLaunchNode.Add(nn5);


            cc.Load(collQuickLaunchNode);
            cc.ExecuteQuery();

            //---

            NavigationNodeCollection qlNodes = newWeb.Navigation.QuickLaunch;

            cc.Load(qlNodes);
            cc.ExecuteQuery();

            qlNodes.ToList().ForEach(node => { if (node.Title == "Recent")
                                               {
                                                   node.DeleteObject();
                                               }
                                     });
            qlNodes.ToList().ForEach(node => { if (node.Title == "Documents")
                                               {
                                                   node.DeleteObject();
                                               }
                                     });
            qlNodes.ToList().ForEach(node => { if (node.Title == "Notebook")
                                               {
                                                   node.DeleteObject();
                                               }
                                     });
            qlNodes.ToList().ForEach(node => { if (node.Title == "Home")
                                               {
                                                   node.DeleteObject();
                                               }
                                     });

            cc.ExecuteQuery();
            //returnera webb
            return(newLib.DefaultViewUrl);
        }
Пример #26
0
 static void CreateTopNavNode(string title, string path)
 {
     string nodeUrl = site.Url + path;
       NavigationNodeCreationInformation newNode = new NavigationNodeCreationInformation();
       newNode.IsExternal = false;
       newNode.Title = title;
       newNode.Url = nodeUrl;
       newNode.AsLastNode = true;
       TopNavNodes.Add(newNode);
       clientContext.ExecuteQuery();
 }
Пример #27
0
        public override void AddNavigationNode(string title, string url, NavigationNodeLocation location)
        {
            NavigationNodeCreationInformation newNavNode = new NavigationNodeCreationInformation();
            newNavNode.Title = title;
            newNavNode.Url = url;

            NavigationNodeCollection navNodeColl = null;
            switch (location)
            {
                case NavigationNodeLocation.TopNavigationBar:
                    navNodeColl = _web.Navigation.TopNavigationBar;
                    break;
                case NavigationNodeLocation.QuickLaunchLists:
                    navNodeColl = _web.Navigation.QuickLaunch;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(location), location, null);
            }

            try
            {
                navNodeColl.Add(newNavNode);
                _context.ExecuteQuery();
            }
            catch (Exception)
            {
                //ignore, vec postoji
            }
        }
Пример #28
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="clientContext"></param>
        /// <param name="web">Web which is already initiated</param>
        /// <param name="siteTemplate"></param>
        private void DeployNavigation(ClientContext clientContext, Web web, XElement siteTemplate)
        {
            XElement navigationNodesToCreate = siteTemplate.Element("NavigationNodes");
            if (navigationNodesToCreate != null)
            {
                foreach (XElement navigationNodeToCreate in navigationNodesToCreate.Elements())
                {
                    // Let's create the nodes based on configuration to quick launch
                    NavigationNodeCreationInformation nodeInformation = new NavigationNodeCreationInformation();
                    nodeInformation.Title = navigationNodeToCreate.Attribute("Title").Value;
                    nodeInformation.Url = navigationNodeToCreate.Attribute("Url").Value;

                    clientContext.Load(web.Navigation.QuickLaunch);
                    clientContext.ExecuteQuery();
                    web.Navigation.QuickLaunch.Add(nodeInformation);

                    clientContext.ExecuteQuery();
                }
            }
        }
Пример #29
0
        /// <summary>
        /// Creates a navigation node as a child of another (first or second level) navigation node.
        /// </summary>
        /// <param name="web">Site to be processed - can be root web or sub site</param>
        /// <param name="parentNodes">Level one nodes under which the node should be created</param>
        /// <param name="nodeToCreate">Node information</param>
        /// <param name="parentNodeTitle">The title of the immediate parent node (level two if child should be level three, level one otherwise)</param>
        /// <param name="l1ParentNodeTitle">The level one parent title or null, if the node to be created should be a level two node</param>
        /// <returns></returns>
        private static NavigationNode CreateNodeAsChild(Web web, NavigationNodeCollection parentNodes, NavigationNodeCreationInformation nodeToCreate, string parentNodeTitle, string l1ParentNodeTitle)
        {
            if (l1ParentNodeTitle != null)
            {
                var l1ParentNode = parentNodes.FirstOrDefault(n => n.Title.Equals(l1ParentNodeTitle, StringComparison.InvariantCultureIgnoreCase));
                if (l1ParentNode == null)
                {
                    return(null);
                }
                web.Context.Load(l1ParentNode.Children);
                web.Context.ExecuteQueryRetry();
                parentNodes = l1ParentNode.Children;
            }

            var parentNode     = parentNodes.FirstOrDefault(n => n.Title.Equals(parentNodeTitle, StringComparison.InvariantCultureIgnoreCase));
            var navigationNode = parentNode?.Children.Add(nodeToCreate);

            return(navigationNode);
        }