我无法获取我的 SharePoint ListItem 字段
我想显示某个 ListItem 的所有字段。这包括 LookUpFields 和 ChoiceFields。但我似乎只能显示文本字段,例如标题。如何显示 ListItem 的所有字段? 问题是,当我尝试以显示“标题”的方式显示列表项的其他字段时,出现错误,就好像我输入的字符串不作为该列表项中的字段存在一样。但它们确实存在并且充满了价值观! 显示列表项的自定义字段而不出现 ObjectReference 错误的好方法是什么? 我还收到此错误:字典中不存在给定的键。
private void foo()
{
using (ClientContext context = new ClientContext(ApplicationContext.Current.Url))
{
_list = context.Web.Lists.GetByTitle("MyList").Title);
_items = _list.GetItems(CamlQuery.CreateAllItemsQuery());
context.Load(_items);
context.ExecuteQueryAsync(
new ClientRequestSucceededEventHandler(OnListItemsRequestSucceeded),
new ClientRequestFailedEventHandler(OnListItemsRequestFailed));
}
}
private void OnListItemsRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
{
// this is not called on the UI thread
Dispatcher.BeginInvoke(ShowListItemDetails);
}
public void ShowListItemDetails()
{
foreach (ListItem i in _items)
{
TextBox_Details.Text += i["Title"].ToString() + Environment.NewLine;
// Now the rest of the fields of this item.
}
}
编辑:还有一个大问题是我无法让调试器工作。此代码作为 Silverlight Web 部件在本地 Sharepoint 站点上运行。我将调试器附加到 iexplorer.exe 但它不会中断。 如果我能让调试器工作,那确实会有很大的帮助。
I want to show all fields of a certain ListItem. This includes LookUpFields and ChoiceFields. But I only seem to be able to show Textfields, like Title. How can I show all fields of my ListItem?
The problem is that I get an error when I try to show other fields of a listitem the way I got 'Title' to show, as if the strings I type in don't exist as fields in that listitem. But they do exist and are populated with values!
What is good way to show custom fields of a listitem without getting ObjectReference errors?
Also I get this error: The given key was not present in the dictionary.
private void foo()
{
using (ClientContext context = new ClientContext(ApplicationContext.Current.Url))
{
_list = context.Web.Lists.GetByTitle("MyList").Title);
_items = _list.GetItems(CamlQuery.CreateAllItemsQuery());
context.Load(_items);
context.ExecuteQueryAsync(
new ClientRequestSucceededEventHandler(OnListItemsRequestSucceeded),
new ClientRequestFailedEventHandler(OnListItemsRequestFailed));
}
}
private void OnListItemsRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
{
// this is not called on the UI thread
Dispatcher.BeginInvoke(ShowListItemDetails);
}
public void ShowListItemDetails()
{
foreach (ListItem i in _items)
{
TextBox_Details.Text += i["Title"].ToString() + Environment.NewLine;
// Now the rest of the fields of this item.
}
}
Edit: What also is a big problem is I cant get the debugger working. This code is running as a Silverlight webpart on a local Sharepoint site. I attach the debugger to the iexplorer.exe but it won't break.
If I could get the debugger to work it would be a great help indeed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您已告诉查询需要从列表中提取哪些字段
以获取更多详细信息
http://msdn.microsoft.com/en-us/library/ee857094.aspx#SP2010ClientOM_Accessing_Large_Lists
you have tell the query what all fields you need to pull from lists
for more details
http://msdn.microsoft.com/en-us/library/ee857094.aspx#SP2010ClientOM_Accessing_Large_Lists
要获取项目属性,您需要在 ClientContext.Load 方法的第二个参数中指定所需的所有项目属性,
例如
To get item properties you will need to specify all the item properties you need in the second parameter of the ClientContext.Load method
e.g