如何在 SharePoint 中以编程方式创建 KPI 列表?

发布于 2024-08-28 09:14:09 字数 50 浏览 6 评论 0原文

我希望能够通过对象模型在我的 MOSS 2007 安装上创建 KPI 列表。这可能吗?

I want to be able to create a KPI List on my MOSS 2007 installation via the object model. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

音盲 2024-09-04 09:14:19

这对我来说是工作:

   private void CreateKPIDocumentLibrary(List<PageStructure> list)
    {
        SPListTemplate kpi = null;
        foreach (SPListTemplate t in web.ListTemplates)
        {
            if (t.Type.ToString() == "432")
            {
                kpi = t;
                break;
            }
        }

        foreach (PageStructure st in list)
        {
            bool find = false;
            string[] periodType = st.tag.Split('_');
            string name = periodType[0] + "-" + st.effdate + "-" + st.template;
            SPListCollection lstCol = site.OpenWeb().GetListsOfType(SPBaseType.GenericList);
            foreach (SPList l in lstCol)
            {
                string title = l.Title;
                if (title == name)
                {
                    find = true;
                    break;
                }
            }

            if (find == false)
            {
                Guid docLibID = web.Lists.Add(name, "", kpi);
            }

            SPList itemList = web.Lists[name];
            SPListItem item = itemList.Items.Add();
            SPFieldUrlValue value = new SPFieldUrlValue();
            item["Title"] = st.tag;
            value.Url = st.docUrl;
            item["DetailLink"] = st.url;
            item["DataSource"] = value;
            item["Indicator Goal Threshold"] = "2";
            item["Indicator Warning Threshold"] = "1";
            item["View Name"] = "All Documents";
            item.SystemUpdate();
            web.Update();
            KpiObject kp = new KpiObject(name, SPContext.Current.Site.Url + itemList.DefaultViewUrl);
            this.kpiList.Add(kp);
        }
    }

this is work for me:

   private void CreateKPIDocumentLibrary(List<PageStructure> list)
    {
        SPListTemplate kpi = null;
        foreach (SPListTemplate t in web.ListTemplates)
        {
            if (t.Type.ToString() == "432")
            {
                kpi = t;
                break;
            }
        }

        foreach (PageStructure st in list)
        {
            bool find = false;
            string[] periodType = st.tag.Split('_');
            string name = periodType[0] + "-" + st.effdate + "-" + st.template;
            SPListCollection lstCol = site.OpenWeb().GetListsOfType(SPBaseType.GenericList);
            foreach (SPList l in lstCol)
            {
                string title = l.Title;
                if (title == name)
                {
                    find = true;
                    break;
                }
            }

            if (find == false)
            {
                Guid docLibID = web.Lists.Add(name, "", kpi);
            }

            SPList itemList = web.Lists[name];
            SPListItem item = itemList.Items.Add();
            SPFieldUrlValue value = new SPFieldUrlValue();
            item["Title"] = st.tag;
            value.Url = st.docUrl;
            item["DetailLink"] = st.url;
            item["DataSource"] = value;
            item["Indicator Goal Threshold"] = "2";
            item["Indicator Warning Threshold"] = "1";
            item["View Name"] = "All Documents";
            item.SystemUpdate();
            web.Update();
            KpiObject kp = new KpiObject(name, SPContext.Current.Site.Url + itemList.DefaultViewUrl);
            this.kpiList.Add(kp);
        }
    }
随波逐流 2024-09-04 09:14:18
using (SPWeb web1 = properties.Feature.Parent as SPWeb)
{
    using (SPSite objSite = new SPSite(web1.Site.ID))                             
    {
        using (SPWeb web = objSite.OpenWeb(web1.ID))
        {
            SPListTemplate template = null;
            foreach (SPListTemplate t in web.ListTemplates)
            {
                if (t.Type.ToString() == "432")
                {
                    template = t;
                    break;
                }
            }
            Guid gG = Guid.Empty;
            SPList list = null;
            string sListTitle = "Status List";
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                try
                {
                    web.AllowUnsafeUpdates = true;
                    gG = web.Lists.Add(sListTitle, sListTitle, template);
                    list = web.Lists[gG];
                }
                catch
                {
                    // exists
                    list = web.Lists[sListTitle];
                }
                SPContentType ct =
                  list.ContentTypes["SharePoint List based Status Indicator"];

                //declare each item which u want to insert in the kpi list
                SPListItem item1 = list.Items.Add();

                SPFieldUrlValue value1 = new SPFieldUrlValue();

                item1["ContentTypeId"] = ct.Id;
                item1.SystemUpdate();
                item1["Title"] = "Project Specific Doc.Lib.Rating";
                value1.Url = web.Url + "/Lists/Project Specific Documents";
                item1["DataSource"] = value1;
                item1["Indicator Goal Threshold"] = "3";
                item1["Indicator Warning Threshold"] = "3";
                item1["Value Expression"] =
                  "Average;Average_x0020_Rating:Number";
                item1.SystemUpdate();
            }
        }
    }

average 为计算值,列为 Average_x0020_Rating

using (SPWeb web1 = properties.Feature.Parent as SPWeb)
{
    using (SPSite objSite = new SPSite(web1.Site.ID))                             
    {
        using (SPWeb web = objSite.OpenWeb(web1.ID))
        {
            SPListTemplate template = null;
            foreach (SPListTemplate t in web.ListTemplates)
            {
                if (t.Type.ToString() == "432")
                {
                    template = t;
                    break;
                }
            }
            Guid gG = Guid.Empty;
            SPList list = null;
            string sListTitle = "Status List";
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                try
                {
                    web.AllowUnsafeUpdates = true;
                    gG = web.Lists.Add(sListTitle, sListTitle, template);
                    list = web.Lists[gG];
                }
                catch
                {
                    // exists
                    list = web.Lists[sListTitle];
                }
                SPContentType ct =
                  list.ContentTypes["SharePoint List based Status Indicator"];

                //declare each item which u want to insert in the kpi list
                SPListItem item1 = list.Items.Add();

                SPFieldUrlValue value1 = new SPFieldUrlValue();

                item1["ContentTypeId"] = ct.Id;
                item1.SystemUpdate();
                item1["Title"] = "Project Specific Doc.Lib.Rating";
                value1.Url = web.Url + "/Lists/Project Specific Documents";
                item1["DataSource"] = value1;
                item1["Indicator Goal Threshold"] = "3";
                item1["Indicator Warning Threshold"] = "3";
                item1["Value Expression"] =
                  "Average;Average_x0020_Rating:Number";
                item1.SystemUpdate();
            }
        }
    }

average is the calculation value and the column is Average_x0020_Rating.

北音执念 2024-09-04 09:14:18

http://alonsorobles.com/2010/03 /17/important-custom-sharepoint-list-template-notes/

我发现状态指示器(KPI 列表)的模板 ID 是 432。通过 Google 查找有关创建新列表的一些信息。我需要了解我可以在此列表上设置哪些属性。

http://alonsorobles.com/2010/03/17/important-custom-sharepoint-list-template-notes/

I found that the Template ID for a Status Indicator (KPI List) is 432. Google for this to find some info on creating a new list. I'm needing to read up what properties I can set on this list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文