示例#1
0
        private StructuralNavigation GetStructuralNavigation(Web web, WebNavigationSettings navigationSettings, Enums.NavigationType navigationType, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
        {
            // By default avoid removing existing nodes
            var result = new StructuralNavigation {
                RemoveExistingNodes = false
            };

            Microsoft.SharePoint.Client.NavigationNodeCollection sourceNodes = navigationType == Enums.NavigationType.QuickLaunch ?
                                                                               web.Navigation.QuickLaunch : navigationType == Enums.NavigationType.TopNavigationBar ? web.Navigation.TopNavigationBar : web.LoadSearchNavigation();

            if (sourceNodes == null)
            {
                return(result);
            }

            var clientContext = web.Context;

            clientContext.Load(web, w => w.ServerRelativeUrl, w => w.Language);
            clientContext.Load(sourceNodes);
            clientContext.ExecuteQueryRetry();
            var defaultCulture = new CultureInfo((int)web.Language);

            if (!sourceNodes.ServerObjectIsNull.Value)
            {
                result.NavigationNodes.AddRange(from n in sourceNodes.AsEnumerable()
                                                select n.ToDomainModelNavigationNode(web, creationInfo.PersistMultiLanguageResources, defaultCulture));

                if (creationInfo.PersistMultiLanguageResources)
                {
                    //need to get nodes and children for any other then default language
                    foreach (var language in template.SupportedUILanguages.Where(c => c.LCID != defaultCulture.LCID))
                    {
                        var currentCulture = new CultureInfo(language.LCID);
                        clientContext.Load(web, w => w.ServerRelativeUrl);
                        clientContext.Load(sourceNodes);
                        var acceptLanguage = clientContext.PendingRequest.RequestExecutor.WebRequest.Headers["Accept-Language"];
                        clientContext.PendingRequest.RequestExecutor.WebRequest.Headers["Accept-Language"] = currentCulture.Name;
                        clientContext.ExecuteQueryRetry();

                        if (!sourceNodes.ServerObjectIsNull.Value)
                        {
                            //we dont need to add to result - just extract Titles - to List as we need to
                            var alternateLang = (from n in sourceNodes.AsEnumerable()
                                                 select n.ToDomainModelNavigationNode(web, creationInfo.PersistMultiLanguageResources, currentCulture)).ToList();
                        }

                        clientContext.PendingRequest.RequestExecutor.WebRequest.Headers["Accept-Language"] = acceptLanguage;
                    }
                }
            }
            return(result);
        }
示例#2
0
        public void AddJsLink(Microsoft.SharePoint.Client.ClientContext ctx)
        {
            Web web = ctx.Web;

            ctx.Load(web, w => w.UserCustomActions);
            ctx.ExecuteQuery();

            ctx.Load(web, w => w.UserCustomActions, w => w.Url, w => w.AppInstanceId);
            ctx.ExecuteQuery();

            UserCustomAction userCustomAction = web.UserCustomActions.Add();

            userCustomAction.Location = "Microsoft.SharePoint.StandardMenu";
            userCustomAction.Group    = "SiteActions";
            BasePermissions perms = new BasePermissions();

            perms.Set(PermissionKind.ManageWeb);
            userCustomAction.Rights   = perms;
            userCustomAction.Sequence = 100;
            userCustomAction.Title    = "Say Hello";

            string url = "javascript:alert('Hello SharePoint Custom Action!!!');";


            userCustomAction.Url = url;
            userCustomAction.Update();
            ctx.ExecuteQuery();

            // Remove the entry from the 'Recents' node
            Microsoft.SharePoint.Client.NavigationNodeCollection nodes = web.Navigation.QuickLaunch;
            ctx.Load(nodes, n => n.IncludeWithDefaultProperties(c => c.Children));
            ctx.ExecuteQuery();
            var recent = nodes.Where(x => x.Title == "Recent").FirstOrDefault();

            if (recent != null)
            {
                var appLink = recent.Children.Where(x => x.Title == "Site Modifier").FirstOrDefault();
                if (appLink != null)
                {
                    appLink.DeleteObject();
                }
                ctx.ExecuteQuery();
            }
        }
        private StructuralNavigation GetStructuralNavigation(Web web, WebNavigationSettings navigationSettings, Boolean currentNavigation)
        {
            // By default avoid removing existing nodes
            var result = new StructuralNavigation {
                RemoveExistingNodes = false
            };

            Microsoft.SharePoint.Client.NavigationNodeCollection sourceNodes = currentNavigation ?
                                                                               web.Navigation.QuickLaunch : web.Navigation.TopNavigationBar;

            web.Context.Load(web, w => w.ServerRelativeUrl);
            web.Context.Load(sourceNodes);
            web.Context.ExecuteQueryRetry();

            result.NavigationNodes.AddRange(from n in sourceNodes.AsEnumerable()
                                            select n.ToDomainModelNavigationNode(web));

            return(result);
        }