首页 > 代码库 > SharePoint 站点集和子站点数据互相读取
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(); }
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; }
SharePoint 站点集和子站点数据互相读取
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。