对sharepoint的C#CAML查询返回列表中的所有项目(而不是仅查找mach查询值的项目)

had*_*w64 2 c# sharepoint caml

我的应用程序中有以下代码从sharepoint列表中提取详细信息.

            string siteUrl = "http://SHAREPOINTURL";

        ClientContext clientContext = new ClientContext(siteUrl);
        clientContext.Credentials = new NetworkCredential("UN", "PW", "DOMAIN");
        SP.List oList = clientContext.Web.Lists.GetByTitle("Licences");

        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml = "<Where><Eq><FieldRef Name='Account' /><Value Type='Text'>123456</Value></Eq></Where>";

        ListItemCollection collListItem = oList.GetItems(camlQuery);
        clientContext.Load(collListItem);
        clientContext.ExecuteQuery();

        Console.WriteLine("Filtered List: " + collListItem.Count.ToString() + "\n");
        foreach (ListItem oListItem in collListItem)
        {
            Console.WriteLine("Account: {0} \nLicence: {1} \nMAC: {2}\n", oListItem["Account"], oListItem["Licence"], oListItem["MAC"]);
        }
Run Code Online (Sandbox Code Playgroud)

在sharepoint列表中,我创建了多个测试项,但每次运行上面的代码时,无论我使用什么用于camlQuery,都会返回列表中的所有项.

任何人都可以让我知道我对C#这个新手的错误,并且在此之前从未触及过sharepoint.

Edit1:根据以下建议更新.

Edit2:简化了代码但仍然遇到了同样的问题.

小智 5

如果要返回已过滤的项目,在您的情况下返回所有项目,是否正确?如果是的话,这个问题出现在CAMLQuery中......

我已经阅读了一些小文档(链接如下):

Microsoft MSDN

我注意到格式化ViewXml:

camlQuery.ViewXml = "<Where><Eq><FieldRef Name='Account' /><Value Type='Text'>123456</Value></Eq></Where>"
Run Code Online (Sandbox Code Playgroud)

尝试使用此代码:

camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Account' /><Value Type='Text'>123456</Value></Eq></Where></Query></View>"
Run Code Online (Sandbox Code Playgroud)

我和caml一起工作.

一些语法反映:

camlquery.query = "<query> ..... </query>";
camlquery.ViewXml = "<view> ..... </view>";
Run Code Online (Sandbox Code Playgroud)

抱歉我的坏英语:S