Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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);
            }
        }
        public void Execute(ClientContext ctx, NavigationNodeCollection nodes, string title, Uri target)
        {
            Logger.Verbose($"Started executing {nameof(AddNavigationNode)} for title '{title}' with url '{target}'");

            var candidate = nodes.SingleOrDefault(n => n.Title == title);
            if (candidate != null)
            {
                Logger.Warning($"Title '{title}' already on navigation");
                return;
            }

            nodes.Add(new NavigationNodeCreationInformation
            {
                Title = title,
                Url = target.ToString(),
                AsLastNode = true
            });

            ctx.ExecuteQuery();
        }
Ejemplo n.º 4
0
        public void Execute(ClientContext ctx, NavigationNodeCollection nodes, string title, Uri target)
        {
            Logger.Verbose($"Started executing {nameof(AddNavigationNode)} for title '{title}' with url '{target}'");

            var candidate = nodes.SingleOrDefault(n => n.Title == title);

            if (candidate != null)
            {
                Logger.Warning($"Title '{title}' already on navigation");
                return;
            }

            nodes.Add(new NavigationNodeCreationInformation
            {
                Title      = title,
                Url        = target.ToString(),
                AsLastNode = true
            });

            ctx.ExecuteQuery();
        }
Ejemplo n.º 5
0
        private NavigationNode EnsureRootNavigationNode(
            WebModelHost webModelHost,
            NavigationNodeDefinitionBase navigationNodeModel)
        {
            NavigationNodeCollection quickLaunch = null;

            var context = webModelHost.HostWeb.Context;

            var existingNode = GetRootNavigationNode(webModelHost, navigationNodeModel, out quickLaunch);
            var previousNode = quickLaunch.Count > 0 ? quickLaunch.Last() : null;

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existingNode,
                ObjectType       = typeof(NavigationNode),
                ObjectDefinition = navigationNodeModel,
                ModelHost        = webModelHost
            });

            if (existingNode == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new navigation node");

                existingNode = quickLaunch.Add(new NavigationNodeCreationInformation
                {
                    Title        = navigationNodeModel.Title,
                    IsExternal   = navigationNodeModel.IsExternal,
                    Url          = navigationNodeModel.Url,
                    PreviousNode = previousNode
                });

                context.ExecuteQueryWithTrace();
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing navigation node");
            }

            existingNode.Title     = navigationNodeModel.Title;
            existingNode.Url       = navigationNodeModel.Url;
            existingNode.IsVisible = navigationNodeModel.IsVisible;

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = existingNode,
                ObjectType       = typeof(NavigationNode),
                ObjectDefinition = navigationNodeModel,
                ModelHost        = webModelHost
            });

            existingNode.Update();

            context.ExecuteQueryWithTrace();

            return(existingNode);
        }
Ejemplo n.º 6
0
        protected override void ExecuteCmdlet()
        {
            if (Url == null)
            {
                ClientContext.Load(SelectedWeb, w => w.Url);
                ClientContext.ExecuteQueryRetry();
                Url = SelectedWeb.Url;
            }
            if (Parent.HasValue)
            {
                var parentNode = SelectedWeb.Navigation.GetNodeById(Parent.Value);
                ClientContext.Load(parentNode);
                ClientContext.ExecuteQueryRetry();
                var addedNode = parentNode.Children.Add(new NavigationNodeCreationInformation()
                {
                    Title      = Title,
                    Url        = Url,
                    IsExternal = External.IsPresent,
                    AsLastNode = !First.IsPresent
                });
                ClientContext.Load(addedNode);
                ClientContext.ExecuteQueryRetry();
                WriteObject(addedNode);
            }
            else
            {
#pragma warning disable CS0618 // Type or member is obsolete
                if (!string.IsNullOrEmpty(Header))
                {
                    var newNavNode = SelectedWeb.AddNavigationNode(Title, new Uri(Url, UriKind.RelativeOrAbsolute), Header, Location, External.IsPresent, !First.IsPresent);
                    WriteObject(newNavNode);
                }
                else
                {
                    NavigationNodeCollection nodeCollection = null;
                    if (Location == NavigationType.SearchNav)
                    {
                        nodeCollection = SelectedWeb.LoadSearchNavigation();
#if !ONPREMISES
                    }
                    else if (Location == NavigationType.Footer)
                    {
                        nodeCollection = SelectedWeb.LoadFooterNavigation();
#endif
                    }
                    else
                    {
                        nodeCollection = Location == NavigationType.QuickLaunch ? SelectedWeb.Navigation.QuickLaunch : SelectedWeb.Navigation.TopNavigationBar;
                        ClientContext.Load(nodeCollection);
                    }
                    if (nodeCollection != null)
                    {
                        var addedNode = nodeCollection.Add(new NavigationNodeCreationInformation()
                        {
                            Title      = Title,
                            Url        = Url,
                            IsExternal = External.IsPresent,
                            AsLastNode = !First.IsPresent
                        });
                        ClientContext.Load(addedNode);
                        ClientContext.ExecuteQueryRetry();
                        WriteObject(addedNode);
                    }
                    else
                    {
                        throw new Exception("Navigation Node Collection is null");
                    }
                }
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
Ejemplo n.º 7
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);
        }