SharePoint 2013 如何获取当前站点对应的“应用目录”中“适用于SharePoint的应用”列表

一开始我用的是以下方法,根据遍历当前站点下的Web应用程序(Web Application)中所有的网站集(Site Collection),查找模板为“APPCATALOG”的网站集,然后在它的根站点下查找功能标识为“0AC11793-9C2F-4CAC-8F22-33F93FAC18F2”的列表。

这个列表就是“应用目录”下的“适用于SharePoint应用”列表。

public static SPList GetCorporateCatalog(SPWeb web) {
    //SPSite site = GetSiteByWebTemplateId(18, current.Site.WebApplication);
    SPSite site = GetSiteByWebTemplate("APPCATALOG", web.Site.WebApplication);
    SPList list = GetListByTemplateFeatureId("0AC11793-9C2F-4CAC-8F22-33F93FAC18F2", site.RootWeb);
    return list;
}

public static SPList GetListByTemplateFeatureId(string templateFeatureId, SPWeb web) {
    foreach (SPList list in web.Lists) {
        if (string.Equals(list.TemplateFeatureId.ToString(), templateFeatureId, StringComparison.OrdinalIgnoreCase)) {
            return list;
        }
    }
    return null;
}

public static SPSite GetSiteByWebTemplateId(int webTemplateId, SPWebApplication webApplication) {
    foreach (SPSite site in webApplication.Sites) {
        if (site.RootWeb.WebTemplateId == webTemplateId) {
            return site;
        }
    }
    return null;
}

public static SPSite GetSiteByWebTemplate(string webTemplate, SPWebApplication webApplication) {
    foreach (SPSite site in webApplication.Sites) {
        if (string.Equals(site.RootWeb.WebTemplate, webTemplate, StringComparison.OrdinalIgnoreCase)) {
            return site;
        }
    }
    return null;
}

o(╯□╰)o 可是在审阅代码时,同事说这个方法效率太低。于是我猜想肯定有某个地方存储“应用目录”及“适用于SharePoint应用”的标识。于是有了如下的方法:

static readonly Guid CorporateCuratedGallerySettingsFeatureID = new Guid("F8BEA737-255E-4758-AB82-E34BB46F5828");

public static SPList GetCorporateCatalog(SPWeb web) {
    SPFeature settingsFeature = web.Site.WebApplication.Features[CorporateCuratedGallerySettingsFeatureID];
    Guid hostSiteId = new Guid(settingsFeature.Properties["__AppCatSiteId"].Value);
    Guid hostListId = new Guid(settingsFeature.Properties["__AppCatListId"].Value);
    using (SPSite hostSite = new SPSite(hostSiteId))
    using (SPWeb hostWeb = hostSite.RootWeb) {
        SPList corporateCatalog = hostWeb.Lists[hostListId];
        return corporateCatalog;
    }
}

原来在Web应用程序中有个名称为“CorporateCuratedGallerySettings”的功能(Feature),标识(ID)为“F8BEA737-255E-4758-AB82-E34BB46F5828”。它有两个属性:“__AppCatSiteId”,“__AppCatListId”,分别存储的是“应用目录”的标识(网站集ID)和“适用于SharePoint应用”的标识(列表ID)。

O(∩_∩)O~~ 如果你能看懂并且会用到的话,就拿去玩吧。

时间: 2024-08-01 18:52:50

SharePoint 2013 如何获取当前站点对应的“应用目录”中“适用于SharePoint的应用”列表的相关文章

SharePoint 2013 创建我的站点、onedrive

SharePoint 2013 创建我的站点.onedrive 参考:https://technet.microsoft.com/zh-cn/library/ee624362.aspx 策略:https://technet.microsoft.com/zh-cn/library/cc262500.aspx 在管理中心中,单击"应用程序管理",然后单击"创建网站集". 注意指定配额.配置网站和锁定,就创建的是都有选项. 选 择当前站点80,录入一个标题URL 在&qu

SharePoint 2013 代码获取图片库中的大图、小图、原图

SharePoint 2013中,上传一张图片,除原图外,默认生成一张大图.一张小图,可以根据自己的需要将不同的图运用在不同的位置. SPListItemCollection itemColl=GetPicLibraryItemColl(); SPWeb web = SPContext.Current.Web;SPFile sf = spfolder.Files[0];string folderUrl = sf.ParentFolder.Url; string fileName = sf.Nam

在SharePoint 2013上面实施响应式设计

  本文由SPFarmer翻译Ricardo的文章 学习如何在SharePoint上实施响应式设计,以让一个publishing site在不同的分辨率下有不同的显示. 我们都知道,网页设计师对于一个成功的SharePoint实施是至关重要的.基于这一点,我想为网页设计师写一篇文章.在这方面我不是权威的专家,我决定咨询一下在网页设计有资深经验的人.通过询问我的联系人,我得到了SharePointbranding 和UX customization领域的一个专家-- EricOverfield的邮

盘点SharePoint 2013那些优秀的开发工具

盘点SharePoint 2013那些优秀的开发工具 分类: SharePoint2014-07-18 20:33 277人阅读 评论(0) 收藏 举报 CAML Designer 2013 CAML Designer是帮助生成CAML查询以查询SharePoint列表的一种工具.可以说,目前没有比CAML Designer这样自动生成存根来生成CAML查询更有效的方式了. CAML Designer 2013较之前版本有很大改进,虽现在的功能并非十全十美,但仍无法阻止其成为该领域的最佳选择.它

SharePoint 2013 对二进制大型对象(BLOB)进行爬网

原文:SharePoint 2013 对二进制大型对象(BLOB)进行爬网 本文是参考MSDN文档做的示例,SharePoint 2013搜索二进制对象(BLOB),通过外部内容类型的方式将外部数据与SharePoint相关联,修改BCD模型,使SharePoint能够爬网外部数据中的文件流. 步骤,首先就是使用SPD创建外部内容类型,并为外部内容类型添加各种操作:然后,将BCD模型导出,添加方法后重新导入:最后,配置爬网,对外部内容类型进行爬网. 1.首先,用Designer 2013打开站点

安装和配置SharePoint 2013 Workflow

SharePoint 2013中的工作流概述 安装并配置工作流管理器 配置工作流管理器 与 SharePoint Server 2013 一起使用 测试是否正确安装和配置SharePoint Workflow 2013 小结 SharePoint 2013中的工作流概述 在SharePoint 2013中,Workflow(建立在Windows Workflow Foundation 4.5)和WCF承载在Workflow Manager中,即Workflow Manager提供了工作流定义的管

安装和配置SharePoint 2013 with SP1 Workflow

安装和配置SharePoint 2013 with SP1 Workflow SharePoint 2013 with SP1中的工作流概述 在SharePoint 2013 with SP1中,Workflow(建立在Windows Workflow Foundation 4.5)和WCF承载在Workflow Manager中,即Workflow Manager提供了工作流定义的管理,还承载了工作流实例的执行过程,是新的工作流引擎.为了侦听工作流的SharePoint事件(如itemCrea

SharePoint 2013 工作流之使用Designer配置示例篇

原文:SharePoint 2013 工作流之使用Designer配置示例篇 在SharePoint 2013中,支持SharePoint Designer 2013(以下简称SPD)配置简单的工作流,完成我们的业务需要.下面,我们就举一个小例子,实现SPD配置工作流. 1. 首先,打开SPD,打开SharePoint站点,在Ribbon菜单上,选择列表工作流,选择需要配置的列表,如下图: 2.弹出对话框,如下图,填写工作流名称.说明及平台类型: 3.进入工作流设计器,如下图: 4.在Ribbo

[转]SharePoint 2013 App 开发 (2) - 建立开发环境

这篇文章属于SharePoint 2013 App开发系列文章,到这篇文章为止,此系列的文章包括: SharePoint 2013 App开发 (1) - 什么是SharePoint App? SharePoint 2013 App开发 (2) - 建立开发环境 (本文) 在开发SharePoint App之前,开发人员需要有一个SharePoint开发环境.无论是开发何种类型的应用程序,开发人员都需要在开发机器上准备相应的开发环境.比如,如果是开发ASP.NET Web应用,那么在开发机器上除