Exemplo n.º 1
0
        public static string GetWebUrl(this SPClient.Web web)
        {
            if (!web.IsPropertyAvailable("Title"))
            {
                web.Context.Load(web);
                web.Context.ExecuteQuery();
            }

            return(string.Format("{0}/{1}", web.Context.Url, web.ServerRelativeUrl.ToLower().Replace(new Uri(web.Context.Url.ToLower()).AbsolutePath, "")));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the URL for the current web.
        /// </summary>
        /// <param name="web"></param>
        /// <returns></returns>
        public static string GetUrl(this SPClient.Web web)
        {
            if (!web.IsPropertyAvailable("Url"))
            {
                web.Context.Load(web);
                web.Context.ExecuteQuery();
            }

            return(web.Url);
        }
Exemplo n.º 3
0
        public static TreeNode LoadWeb(TreeNode parentNode, SPClient.Web web, MainBrowser form)
        {
            if (!web.IsPropertyAvailable("Title"))
            {
                SPClient.ClientContext ctx = GetClientContext(parentNode);
                ctx.Load(web);
                ctx.Load(web, w => w.AllowDesignerForCurrentUser,
                         w => w.AllowMasterPageEditingForCurrentUser,
                         w => w.AllowRevertFromTemplateForCurrentUser,
                         w => w.HasUniqueRoleAssignments,
                         w => w.ShowUrlStructureForCurrentUser);
                ctx.ExecuteQuery();
            }

            TreeNode node = parentNode.Nodes.Add(string.Format("{0} ({1})", web.Title, web.ServerRelativeUrl));

            node.ImageKey         = Constants.IMAGE_SITE;
            node.SelectedImageKey = Constants.IMAGE_SITE;
            node.ContextMenuStrip = form.mnContextItem;
            node.Tag = web;

            AddLoadingNode(node, "Webs", "Returns the collection of child sites of the current site based on the specified query.", Constants.IMAGE_WEB, LoadType.WebSubWebs);
            AddLoadingNode(node, "Site Columns", "Gets the collection of field objects that represents all the fields in the Web site.", Constants.IMAGE_SITE_COLUMN, LoadType.WebFields);
            AddLoadingNode(node, "Content Types", "Gets the collection of content types for the Web site.", Constants.IMAGE_CONTENT_TYPE, LoadType.WebContentTypes);
            AddLoadingNode(node, "Lists", "Gets the collection of all lists that are contained in the Web site available to the current user based on the current user’s permissions.", Constants.IMAGE_LIST, LoadType.WebLists);
            AddLoadingNode(node, "Features", "Gets a value that specifies the collection of features that are currently activated in the site.", Constants.IMAGE_FEATURE, LoadType.WebFeatures);
            AddLoadingNode(node, "Site Users", "Gets the UserInfo list of the site collection that contains the Web site.", Constants.IMAGE_SITE_USER, LoadType.WebUsers);
            AddLoadingNode(node, "Site Groups", "Gets the collection of groups for the site collection.", Constants.IMAGE_SITE_GROUP, LoadType.WebGroups);
            AddLoadingNode(node, "Workflow Associations", "Gets a value that specifies the collection of all workflow associations for the site.", Constants.IMAGE_WORKFLOW_ASSOCIATION, LoadType.WebWorkflowAssociations);
            AddLoadingNode(node, "Workflow Templates", "Gets a value that specifies the collection of all workflow associations for the site.", Constants.IMAGE_WORKFLOW_TEMPLATE, LoadType.WebWorkflowTemplates);
            AddLoadingNode(node, "Properties", Constants.IMAGE_PROPERTY, LoadType.WebProperties);
            AddLoadingNode(node, "List Templates", Constants.IMAGE_LIST_TEMPLATES, LoadType.WebListTemplates);
            AddLoadingNode(node, "Role Assignments", Constants.IMAGE_ROLE_ASSIGNMENT, LoadType.WebRoleAssignments);
            AddLoadingNode(node, "Role Definitions", Constants.IMAGE_ROLE_DEFINITIONS, LoadType.WebRoleDefinitions);
            AddLoadingNode(node, "Web Templates", Constants.IMAGE_WEB_TEMPLATES, LoadType.WebTemplates);

            // Add root folder
            LoadFolder(node, web.RootFolder, form, true);

            return(node);
        }
Exemplo n.º 4
0
        private Microsoft.SharePoint.Client.Web GetWeb()
        {
            Microsoft.SharePoint.Client.Web web = ClientContext.Web;

            if (Web.Id != Guid.Empty)
            {
                web = web.GetWebById(Web.Id);
                SPOnlineConnection.CurrentConnection.Context = this.ClientContext.Clone(web.Url);
                web = SPOnlineConnection.CurrentConnection.Context.Web;
            }
            else if (!string.IsNullOrEmpty(Web.Url))
            {
                web = web.GetWebByUrl(Web.Url);
                SPOnlineConnection.CurrentConnection.Context = this.ClientContext.Clone(web.Url);
                web = SPOnlineConnection.CurrentConnection.Context.Web;
            }
            else if (Web.Web != null)
            {
                web = Web.Web;
                if (!web.IsPropertyAvailable("Url"))
                {
                    ClientContext.Load(web, w => w.Url);
                    ClientContext.ExecuteQuery();
                }
                SPOnlineConnection.CurrentConnection.Context = this.ClientContext.Clone(web.Url);
                web = SPOnlineConnection.CurrentConnection.Context.Web;
            }
            else
            {
                if (SPOnlineConnection.CurrentConnection.Context.Url != SPOnlineConnection.CurrentConnection.Url)
                {
                    SPOnlineConnection.CurrentConnection.RestoreCachedContext();
                    //SPOnlineConnection.CurrentConnection.Context = this.ClientContext.Clone(SPOnlineConnection.CurrentConnection.Url);
                }
                web = ClientContext.Web;
            }


            return(web);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Returns true, if the current web is an App web
 /// </summary>
 /// <param name="web"></param>
 /// <returns></returns>
 public static bool IsAppWeb(this SPClient.Web web)
 {
     return(web.IsPropertyAvailable("AppInstanceId") && web.AppInstanceId != Guid.Empty);
 }