使用 CAML 查询查询共享点中的列表项
我有一个包含三列的列表:1)标题,2)登录用户3)ParentSiteAccess。如果特定用户登录,那么我需要获取第三列的值(即 ParentSiteAccess)。 我正在使用下面的查询来获取它。
query.Query = @"<Where><Eq><FieldRef Name='LoginUser'/><Value Type='Text'>" + userName + "</Value></Eq></Where>";
query.ViewFields = "<FieldRef name='ParentSiteAccess'/><FieldRef name='LoginUser'/>";
query.ViewFieldsOnly = true;
但我不同意这种方法。有人能给我一个有效的解决方案吗?
I have a list with three columns 1)Title,2) LoginUser 3)ParentSiteAccess. If a particular user is logged in then i need to fetch the values of the third column(i.e ParentSiteAccess).
I am using the below query to get it.
query.Query = @"<Where><Eq><FieldRef Name='LoginUser'/><Value Type='Text'>" + userName + "</Value></Eq></Where>";
query.ViewFields = "<FieldRef name='ParentSiteAccess'/><FieldRef name='LoginUser'/>";
query.ViewFieldsOnly = true;
But i am not getting with this approach. Can anybody give me a valid solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的查询看起来格式良好,但如果无法访问您的环境,则很难进行调试。一个常见问题是列的显示名称与其内部名称不匹配。
我能告诉你的最好的事情就是获取一个名为 U2U CAML 查询生成器。 2007 版本与 SP 2010 配合良好
。如果您与 SharePoint 安装不在同一台机器上,请使用“SharePoint Web 服务”进行连接。如果是的话,“对象模型”或“Web 服务”选项都可以使用。
登录后,指向您的列表并使用 UI 构建您的查询。它最好的一点是,您可以通过列的显示名称来选择列,但它会使用它们的内部名称来构建查询。这是一种尝试查询并立即获得有关其返回内容的反馈的快速方法。
当您获得有效的查询时,只需将其从实用程序窗口复制到您的代码中即可。
Your query looks well-formed, but without access to your environment it's very difficult to debug. A common problem is the columns' display names don't match their internal names.
The best thing I can tell you is to get a copy of a handy, free program called U2U CAML Query Builder. The 2007 version works fine with SP 2010.
Connect using "SharePoint Web Services" if you're not on the same box as your SharePoint install. If you are, either the "Object Model" or "Web Services" option will work.
Once logged in, point to your list and use the UI to build your query. The nicest thing about it is that you get to pick columns by their display name, but it builds the query using their internal names. It's a quick way to experiment with a query and get immediate feedback about what it returns.
When you get a query that works, just copy it out of the utility's window and into your code.