English 中文(简体)
How do I create a KPI list programmatically in SharePoint?
原标题:

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

最佳回答

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.

问题回答
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.

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);
        }
    }




相关问题
SharePoint - Approaching Website Storage Limit Email

How can i go about changing the distribution list as well as the email text for the email that goes out to site collection admin when a site collection approaches it s size limit? Thanks for your ...

UI automated testing within SharePoint

I m looking for automated Functional Testing tools that can manipulate SharePoint sites, libraries, and documents thought the web interface. It needs to be extensible enough to handle any custom ...

Enable authorization on sitemap provider

I want to enable Authorization on the Site map provider. We have enabled anonymous access to the site and we want the Site map provider to be visible only to authorized users. I tried ...

SharePoint : web service permission error

I have a sharepoint site, and I am calling a standard sharepoint web service. I create the web service request like this : wsDws.Url = this.SiteAddress + @"/_vti_bin/Dws.asmx"; When I use ...

Sharepoint 2007 Data view Webpart custom parameters

I m sort of new to the custom parameters that can be setup on a DataView Webpart. There are 6 options: - None - Control - Cookie - Form - QueryString - Server Variable I think that None, Cookie and ...

热门标签