在 SharePoint 2010 客户端 API 中获取 listItem 的字段名称 - (强类型?)
我对 SharePoint 非常陌生,正在使用 2010。尝试看看我们可以用它做什么,特别是列表。我有一种感觉,我错过了一些非常明显的东西,但找不到它......
在一个 Sharepoint 网站中,我创建了一个名为“名人”的列表:添加了一些人,弗兰克·西纳特拉等。
- 姓氏:西纳特拉
- 名字:Frank
- 电子邮件地址:[email protected]
- 职位名称:歌手
- 等
然后我一直在尝试将这些信息放入一个简单的 C# 控制台应用程序中,参考并尝试了我找到的许多示例。 但我一直在思考我需要引用的实际 fieldNames(?) 是什么,因为它似乎不是强类型的。但使用“电子邮件地址”之类的东西似乎也不起作用
这是我一直在尝试的一个例子。 来自:如何:检索列表项
string siteUrl = "http://servername/site/";
var clientCtx = new ClientContext(siteUrl);
Microsoft.SharePoint.Client.List oList = clientCtx.Web.Lists.GetByTitle("Famous People");
var camlQuery = new CamlQuery {ViewXml = "<View><RowLimit>100</RowLimit></View>"};
ListItemCollection collListItem = oList.GetItems(camlQuery);
clientCtx.Load(collListItem,
items => items.Include(
item => item.Id,
item => item.DisplayName,
item => item.HasUniqueRoleAssignments));
clientCtx.ExecuteQuery();
foreach (ListItem oListItem in collListItem)
{
Console.WriteLine("ID: {0} \nDisplay name: {1} \nUnique role assignments: {2}",
oListItem.Id, oListItem.DisplayName, oListItem.HasUniqueRoleAssignments);
}
Console.ReadLine();
clientCtx.Dispose();
(
ID: 1
Display name: Clough
Unique role assignments: False
ID: 2
Display name: Sinatra
Unique role assignments: False
ID: 3
Display name: Simpson
Unique role assignments: False
ID: 4
Display name: Skywalker
Unique role assignments: False
)已尝试过我上面提供的示例链接中的每种方法。但从那里我不知道如何访问其他属性,例如“工作”或“电子邮件地址”。
或者例如,如果我正在处理一个我不知道的列表,我如何通过网络服务从我的应用程序中找到有效的字段名称?
谢谢。
I'm very new to SharePoint, using 2010. Trying to see what we can do with it, in particular with Lists. And I have a feeling I'm missing something pretty obvious, but can't find it.....
In a Sharepoint site I created a list called Famous People: Added a few people in, Frank Sinatra etc.
- Last Name: Sinatra
- First Name: Frank
- E-mail Address: [email protected]
- Job Title: Singer
- etc
So then I've been trying to get that information into a simple C# console application, referring and trying many examples I have found.
But I get stuck around working out what the actual fieldNames(?) are that I need to refer to, as it doesn't appear to be strongly typed. But also using the likes of "E-mail Address" doesn't seem to work either
Here's one example I've been trying. (From: How to: Retrieve List Items)
string siteUrl = "http://servername/site/";
var clientCtx = new ClientContext(siteUrl);
Microsoft.SharePoint.Client.List oList = clientCtx.Web.Lists.GetByTitle("Famous People");
var camlQuery = new CamlQuery {ViewXml = "<View><RowLimit>100</RowLimit></View>"};
ListItemCollection collListItem = oList.GetItems(camlQuery);
clientCtx.Load(collListItem,
items => items.Include(
item => item.Id,
item => item.DisplayName,
item => item.HasUniqueRoleAssignments));
clientCtx.ExecuteQuery();
foreach (ListItem oListItem in collListItem)
{
Console.WriteLine("ID: {0} \nDisplay name: {1} \nUnique role assignments: {2}",
oListItem.Id, oListItem.DisplayName, oListItem.HasUniqueRoleAssignments);
}
Console.ReadLine();
clientCtx.Dispose();
Which brings back:
ID: 1
Display name: Clough
Unique role assignments: False
ID: 2
Display name: Sinatra
Unique role assignments: False
ID: 3
Display name: Simpson
Unique role assignments: False
ID: 4
Display name: Skywalker
Unique role assignments: False
I have tried each of the methods on the examples link I provided above. But from there I have no idea how to get to the other properties such as "Job", or "E-mail address".
Or for example if I'm dealing with a List which I don't know, how do I find out the valid field names from my application via web service?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
需要注意的是,每个 SPListItem 都有一组不同的字段,具体取决于基础内容类型。
这也会根据该项目所在的列表进行修改。
因此,这就是为什么字段中没有强类型索引的原因...
但是,添加以下代码应该可以帮助您了解每个列表项中的内容
。属性 SPField.SchemaXml 显示每个字段配置的完整详细信息。
拥有 SharePointManager 的副本将使您很好地了解任何给定网站如何组合在一起。
如果只能使用客户端对象模型来发现这一点
The thing to be aware of is that each SPListItem has a different set of field depending on the underlying content type.
This is also modified depending on which list the item is sitting in.
So this is why there is no strongly typed indexing into the fields...
However, adding the following code should help you get a feel for what is inside each listitem
The property SPField.SchemaXml shows the full detail on the configuration of each field.
Having a copy of SharePointManager will give you a good idea of how any given site hangs together.
If you can only use the client object model to discover this
您可以通过索引属性< /a> 在
ListItem
上。您必须将属性添加为
ViewFields
到ViewXml
:注意空格的
_x0020_
编码。You can access the other properties via the indexed property on the
ListItem
.You have to add the properties as
ViewFields
to theViewXml
:Note the
_x0020_
encoding for spaces.如果您进入列表设置,您可以通过单击找到列名称。这会将您发送到如下链接: http://servername/_layouts/FldEdit.aspx?List=%7BEACD90E2%2DED64%2D42EE%2DB1FB%2D2631687C545F%7D&Field=Title
字段的名称是 Field=Title 的 RHS。
如果您知道列名称,则可以使用以下代码:
If you go to your list settings you can find the column name by clicking on it. This will send you to a link like: http://servername/_layouts/FldEdit.aspx?List=%7BEACD90E2%2DED64%2D42EE%2DB1FB%2D2631687C545F%7D&Field=Title
The name of the field is the RHS of Field=Title.
Given that you know the column names you can use the following code: