嘿,我有一个供管理员使用的表单,他们在其中插入用户名(“域\名称”),代码从中获取和设置一些信息。
这是一个巨大的项目,有些列表包含字符串形式的用户名(“域名\名称”),但有些列表仅依赖于自动创建的“创建者”列。
我想知道使用用户名字符串查询这些列表的最快方法是什么。我尝试使用与第一种列表相同的查询,但它显然不起作用 -
<Where><Eq><FieldRef Name='UserName'/><Value Type='Text'>domain\\username</Value></Eq></Where>
谢谢。
Hey, I have a form for administrators where they insert a user name ("domain\name") and the code gets and sets some information out of it.
It's a huge project and some of the lists contain the username as a string ("domain\name"), but some lists only count on the "Created By" column, which is auto-created.
I want to know what's the fastest way to query these lists using the username string. I tried to use the same query as the one I use for the first kind of lists and it obviously didn't work -
<Where><Eq><FieldRef Name='UserName'/><Value Type='Text'>domain\\username</Value></Eq></Where>
Thank you.
发布评论
评论(2)
有两个不同的“创建者”字段,一个用于所有项目,另一个专门用于文档库(“文档创建者”)。 “创建者”字段的内部名称是“作者”,因此
将是最好的开始。第二个字段是文档库中实际文件的作者,其内部名称为“Created_x0020_By”。从你的场景来看,我有一种感觉你只需要前者,但无论如何知道后者是很好的,因为它们存储的数据是不同的。“创建者”是一个用户字段,因此其数据的字符串版本为
ID;#Full Name
。同时,“文档创建者”是单行文本的文本字段,其数据存储为实际用户名(带有域,如果适用)。因此,您的上述查询适用于文档库并在
上进行搜索。但是,如果您想在“创建者”字段中进行搜索,则需要稍微复杂一些,但您应该能够通过引用用户的 SharePoint ID 来完成此操作。以下是我正在使用的不同用户字段查询的示例,以进行比较。这专门过滤掉了当前用户。要将其用于您的目的,请将 'AssignedTo' 替换为 'Author',并将
替换为相关用户的 ID。There are two different "Created By" fields, one for all items and one specifically for document libraries ("Document Created By"). The internal name for the "Created By" field is "Author", so
<FieldRef Name='Author'/>
would be the best start. The second field, which is the author of the actual file in a document library, has an internal name of "Created_x0020_By". Judging from your scenario I have a feeling you'll only need the former, but the latter is good to know anyway, because the data stored in them is different."Created By" is a user field, so the string version of its data is
ID;#Full Name
. Meanwhile, "Document Created By" is a text field for a single line of text, and its data is stored as the actual username (with domain, if applicable). So your above query would work in the case of a document library and searching on<FieldRef Name='Created_x0020_By'/>
. If you wanted to search on the "Created By" field, however, you'll have to be a bit trickier, but you should be able to accomplish it by referencing the user's SharePoint ID. The following is an example of a different User field query that I am using, for comparison.This specifically filtered out the current user. To use it for your purposes, replace 'AssignedTo' with 'Author' and
<UserID Type='Integer' />
with the ID of the user in question.我建议执行以下操作:
通过调用 EnsureUser 方法获取 SharePoint 用户,即:
通过SharePoint-User的ID查询列表:
针对列表触发查询
I would recommend the following:
Get the SharePoint-User by invoking the EnsureUser method, i.e.:
Query the list by using the ID of the SharePoint-User:
Fire the query against the list