zoukankan      html  css  js  c++  java
  • SharePoint 站点集和子站点数据互相读取

    1.站点集中可以使用SPSite.AllWeb,然后遍历所有站点的isRootWeb,根据siteTemplate取得需要的子站点。

    /// <summary>
            /// Handles the Load event of the Page control.
            /// </summary>
            protected void Page_Load(object sender, EventArgs e)
            {
                var web = SPControl.GetContextWeb(Context);
    
                var subSite = new SPSite(web.Site.ID).AllWebs;
    
                var list = new List<ProjectOverviewContent>();
    
                //Foreach sub site
                foreach (SPWeb site in subSite)
                { 
                    if (site.IsRootWeb) continue;
                    if (site.WebTemplate != WebTemplate.PM.ToString()) continue;
    
                    try
                    {
                        var content = site.Lists.TryGetList(ProjectOverviewContent.ProjectListName);
                        if (content == null || content.Items.Count == 0) continue;
    
                        var link = new ProjectOverviewContent
                        {
                            //get sitrUrl
                            SubSiteUrl = site.Url,
                            //get site created time
                            SiteCreateTime = site.Created,
                        };
    
                        //Foreach sub site list => ProjectContent
                        foreach (SPListItem item in content.Items)
                        {
                            link.ProjectName = item[ProjectOverviewContent.ProjectNameMapping].TryToString();
                            link.StartDate = item[ProjectOverviewContent.StartDateMapping].TryToString().SplitDate();
                            link.EndDate = item[ProjectOverviewContent.EndDateMapping].TryToString().SplitDate();
                            link.ServiceLine = item[ProjectOverviewContent.ServiceLineMapping].TryToString();
                            link.Industry = item[ProjectOverviewContent.IndustryMapping].TryToString();
                        }
    
                        content = site.Lists.TryGetList(ProjectOverviewContent.MemberListName);
                        if (content == null)
                        {
                            list.Add(link);
                            continue;
                        }
    
                        //Foreach sub site list => MemberContent
                        foreach (SPListItem item in content.Items)
                        {
                            link.Position = item[ProjectOverviewContent.PositionMapping].TryToString();
    
                            if (link.Position == Position.MIC.ToString())
                            {
                                link.MIC = item[ProjectOverviewContent.MemberNameMapping].TryToString();
                            }
                            else if (link.Position == Position.PIC.ToString())
                            {
                                link.PIC = item[ProjectOverviewContent.MemberNameMapping].TryToString();
                            }
                            else if (link.Position == Position.PM.ToString())
                            {
                                link.PM = item[ProjectOverviewContent.MemberNameMapping].TryToString();
                            }
                        }
    
                        list.Add(link);
                    }
                    catch (SPException spException)
                    {
                        LogHelper.Error(spException);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.ShowError(lblErrorMessage, ex);
                    }
                }
    
                list.Sort();
    
                tblProjectOverview.DataSource = list.Take(10);
                tblProjectOverview.DataBind();
            }
    View Code

    2.子站点读取站点集数据可以通过New SPSite("url").RootWeb获取。

    public SPWeb RootSite = new SPSite(ProjectContent.SiteUrlMapping).RootWeb;
    
    /// <summary>
            /// Gets the project information from root site.
            /// </summary>
            public List<ServiceOfferingContent> GetProjectInfo(string projectCode)
            {
                var siteContent = RootSite.Lists[ServiceOfferingContent.ListName];
                if (siteContent == null || siteContent.Items.Count == 0) return null;
    
                var list = new List<ServiceOfferingContent>();
    
                foreach (SPListItem item in siteContent.Items)
                {
                    var link = new ServiceOfferingContent()
                    {
                        ProjectCode = item[ServiceOfferingContent.ProjectCodeMapping].TryToString(),
                        ServiceLine = item[ServiceOfferingContent.ServiceLineMapping].TryToString(),
                        Industry = item[ServiceOfferingContent.IndustryMapping].TryToString(),
                        Id = item[ServiceOfferingContent.IdMapping].TryToString(),
                        Title = item[ServiceOfferingContent.TitleMapping].TryToString(),
                        Contents = item[ServiceOfferingContent.ContentsMapping].TryToString(),
                        ThumbnailUrl = item[ServiceOfferingContent.ThumbnailUrlMapping].TryToString(),
                        HeadImageUrl = item[ServiceOfferingContent.HeadImageUrlMapping].TryToString(),
                        ContentsImageUrl = item[ServiceOfferingContent.ContentsImageUrlMapping].TryToString(),
                        Summary = item[ServiceOfferingContent.SummaryMapping].TryToString(),
                    };
                    if (link.ProjectCode != projectCode) continue;
                    
                    list.Add(link);
                    return list;
                }
                return null;
            }
    View Code
  • 相关阅读:
    java中的线程是如何工作的。
    springcloud 负载均衡之 ribbon。
    eureka 集群的实现方式?
    eureka的简单介绍,eureka单节点版的实现?eureka的自我保护?eureka的AP性,和CP性?
    docker常用命令、镜像命令、容器命令、数据卷,使用dockerFile创建镜像,dockefile的语法规则。
    关于自动化测试框架的思想和考虑
    Web应用程序压力测试步骤
    自动化测试工具的选择
    软件测试用例的认识误区
    如何评估软件产品的质量?
  • 原文地址:https://www.cnblogs.com/bincoding/p/5832817.html
Copyright © 2011-2022 走看看