我无法获取我的 SharePoint ListItem 字段

发布于 2024-10-11 02:57:12 字数 1326 浏览 2 评论 0原文

我想显示某个 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 技术交流群。

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

发布评论

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

评论(2

这样的小城市 2024-10-18 02:57:12

您已告诉查询需要从列表中提取哪些字段

CamlQuery camlQuery = new CamlQuery();
            camlQuery.ListItemCollectionPosition = itemPosition;
            camlQuery.ViewXml =
                @"<View>
                    <ViewFields>
                      <FieldRef Name='Title'/>
                      <FieldRef Name='Category'/>
                      <FieldRef Name='Estimate'/>
                    </ViewFields>
                    <RowLimit>10</RowLimit>
                  </View>";
            ListItemCollection listItems = list.GetItems(camlQuery);
            clientContext.Load(listItems);
            clientContext.ExecuteQuery();

以获取更多详细信息

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

CamlQuery camlQuery = new CamlQuery();
            camlQuery.ListItemCollectionPosition = itemPosition;
            camlQuery.ViewXml =
                @"<View>
                    <ViewFields>
                      <FieldRef Name='Title'/>
                      <FieldRef Name='Category'/>
                      <FieldRef Name='Estimate'/>
                    </ViewFields>
                    <RowLimit>10</RowLimit>
                  </View>";
            ListItemCollection listItems = list.GetItems(camlQuery);
            clientContext.Load(listItems);
            clientContext.ExecuteQuery();

for more details

http://msdn.microsoft.com/en-us/library/ee857094.aspx#SP2010ClientOM_Accessing_Large_Lists

放赐 2024-10-18 02:57:12

要获取项目属性,您需要在 ClientContext.Load 方法的第二个参数中指定所需的所有项目属性,

例如

        string server = "http://localhost";
        ClientContext context = new ClientContext(server);
       Web web = context.Web;
        var spList = web.Lists.GetByTitle("MyTitle");
        CamlQuery query = new CamlQuery();
        var items = spList.GetItems(query);
        context.Load(items, 
            itema => itema.Include(
                item => item,
                item => item["ComplexProperty"]));
        context.ExecuteQuery();`

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

        string server = "http://localhost";
        ClientContext context = new ClientContext(server);
       Web web = context.Web;
        var spList = web.Lists.GetByTitle("MyTitle");
        CamlQuery query = new CamlQuery();
        var items = spList.GetItems(query);
        context.Load(items, 
            itema => itema.Include(
                item => item,
                item => item["ComplexProperty"]));
        context.ExecuteQuery();`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文