SharePoint任务父母及其子女 [英] SharePoint Tasks Parents and Their Children

查看:71
本文介绍了SharePoint任务父母及其子女的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要提供一个传入任务名称的函数,该函数返回其子ID的列表.我看到子任务有父ID.但是它们的值像1; 1代表多个; 2; 2代表多个,但是所有项目的ID都始于 在我的示例中,从5开始.我希望那些ParentID可以这样做,但显然不会.

I need to come up with a function that I pass in a Task Name and it returns a list of it's children IDs. I see that there are parent IDs for the subtasks. But they have values like 1;1 for several and 2;2 for several, but the IDs of all the items start at in my example start at 5. I had hoped that those ParentID would do it, but apparently not.

这在C#SharePoint控制台应用程序中都是必需的.

This is all needed in a C# SharePoint Console application.

任何对此的建议,将不胜感激.

Any advise on this would be greatly appreciated.

推荐答案

子任务的父ID将被格式化为"1;#1",前1是父任务项ID,另一部分是#1".表示特定父任务下的子任务ID.

Parent ID for a sub task will be formated like "1;#1", the first 1 means the parent task item id, the other part "#1" means the sub task id under the specific parent task.

因此,我们可以拆分父级ID,然后与我们需要查询的给定项目ID进行比较,如果它们相同,则这是我们要获取的子任务:

So we can split the Parent ID and then compare with the given item id we need to query, if they are the same, then this is the sub task we want to get:

       static void getChildTask(string itemid)
        {
            SPSite site = new SPSite("http://sp/sites/dev");
            using (SPWeb web = site.OpenWeb())
            {
                SPList spList = web.Lists.TryGetList("task1");
                if (spList != null)
                {
                    SPQuery qry = new SPQuery();
                    qry.ViewFields = @"<FieldRef Name='ParentID' />";
                    SPListItemCollection listItems = spList.GetItems(qry);
                    foreach (SPListItem item in listItems)
                    {
                        if (item["ParentID"] != null)
                        {
                            string parentitemid = item["ParentID"].ToString().Split(';')[0];
                            if (parentitemid==itemid)
                            {
                                //do logic here
                            }
                        }

                    }
                }

            }

        }

谢谢

最好的问候


这篇关于SharePoint任务父母及其子女的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆