迭代 SPListItem/SPList

发布于 2024-08-06 07:58:15 字数 374 浏览 4 评论 0原文

我正在为人们在我们公司网站上执行任务制定一个清单。 我现在正在开发的功能是,一旦他们完成任务并将其标记为已完成,我希望我们的共享点 Web 部件向他们发送一封电子邮件,其中包含他们仍需要完成的内容的列表。

由于权力者希望能够随意在列表中添加和删除项目,因此它需要模块化,因此检查列表也需要模块化并以模块化术语编写。

我遇到的问题是所有任务都存储在现有代码的 SPList 中。 我不太确定如何遍历列表来查明该人是否已经完成了以下任务。我没有看到任何下一个、上一个、头部或尾部操作(正如我从列表中期望的那样)。由于索引使用字符串,因此它的行为更像是关联数据结构(映射)或数据库中的主键。

请帮忙并谢谢大家!

干杯,

-Jeremiah Tantongco

I'm making a checklist for people to do tasks on our company website.
The feature I'm working on right now is that once they complete a task and mark it as done, I want our sharepoint webpart to send an email to them containing a list of what they still need to finish.

Since the powers that be want to be able to add and subtract items to the list at will, it needs to be modular, therefore checking the list needs to be modular and written in modular terms as well.

The problem that I have is that all the tasks are stored in a SPList on the existing code.
I'm not exactly sure how to iterate over the list to find out whether that person has the done the following task already. I'm not seeing any next, previous, head or tail operations (as I would expect from a list). Since indexing uses a string, it behaves more like an associative data structure (map) or primary key from a DB.

Help please and thanks everyone!

Cheers,

-Jeremiah Tantongco

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

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

发布评论

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

评论(3

舞袖。长 2024-08-13 07:58:15

SharePoint 列表不是计算机科学方式中的列表,而是最终用户期望的列表:事物的列表。

您应该更多地将列表视为类似于数据库表。如果您想根据条件查找表(List)中的记录(Items),那么您应该使用查询。

因此,在 SPList 中查找 SPListItems 的正确方法是使用 SPQuery,在其中以良好的 XML 语法 (CAML) 指定条件,然后将 SPQuery 传递给 SPList.GetItems,从而获取 SPListItems 的集合。

这应该会给你一些谷歌搜索的术语。如果您需要有关查询语法的更多帮助,请使用 U2U Caml 查询生成器或者给我们一些更具体的信息。

A SharePoint list is not a list in the Computer Science way, but is what an End-User would expect a list to be: a listing of things

You should more look at a list as being similar to a database table. If you want to find records (Items) in a table (List) based on conditions then you should use a query.

So the right way to find SPListItems in a SPList is to use an SPQuery where you specify your criteria in a nice XML syntax (CAML), then pass the SPQuery to SPList.GetItems and thereby get a collection of SPListItems back.

This should give you some terms to google for. If you need more help with the syntax of the query then use U2U Caml Query Builder or give us some more specific infomations.

天暗了我发光 2024-08-13 07:58:15

是否应该遍历列表可能是一个有争议的问题,但如果不可避免(就像我的情况一样),可以使用以下代码。

        SPSite siteCollection = new SPSite("http://localhost/");
        SPWeb site = siteCollection.RootWeb;
        SPList myList = site.Lists["My List"];
        SPListItemCollection itemCollection = myList.Items;

        foreach (SPListItem item in itemCollection)
        {
            //Do something with each item
        }

Whether you should iterate through the list or not may be a matter of debate, but if it's unavoidable (as it was in my case) the following code can be used.

        SPSite siteCollection = new SPSite("http://localhost/");
        SPWeb site = siteCollection.RootWeb;
        SPList myList = site.Lists["My List"];
        SPListItemCollection itemCollection = myList.Items;

        foreach (SPListItem item in itemCollection)
        {
            //Do something with each item
        }
海夕 2024-08-13 07:58:15

这可能会解决你的问题

SPList interviewList = myWeb.Lists["listtoiterate"];
foreach (SPListItem interview  in interviewList)
{
// Do Something
} 

This may solve your problem

SPList interviewList = myWeb.Lists["listtoiterate"];
foreach (SPListItem interview  in interviewList)
{
// Do Something
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文