CAML(Collaborative Application Markup Language)——协作应用程序标记语言,在调用WSS提供的诸多Web Service时进行数据查询的一组XML规范,通过这种规范组织查询语句进行数据的检索。我在这里不想再具体介绍CAML的使用规范和具体语法了,读者在MSDN或者园子里的其它文章中都可以了解到。

http://msdn.microsoft.com/zh-cn/library/ms462365.aspx

http://www.cnblogs.com/shanqian/archive/2008/09/25/859513.html

这里我想给出我在项目实际应用中所积累的有关使用CAML查询语句时所解决的问题。

1. Sharepoint的List中允许创建Document和Folder两种类型的数据,在查询时如何查出非Folder类型的数据?

1 <Query> 
2   <Where> 
3      <Neq> 
4        <FieldRef Name="ContentType"/> 
5        <Value Type="Text">Folder</Value> 
6      </Neq> 
7   </Where> 
8 </Query>

当服务器上安装有WSS的多语言包时,根据不同的语言ContentType的值也会有不同的写法,可以借助CAML工具或者在WSS查询返回的报文中查看一下,确认ContentType的具体类型名称。

2. 如何查询List中Lookup类型的字段的值?

Loopup类型的字段在数据库中相当于外键,数据格式如1;#title1;#2;#title2,查询时可以按照下面的CAML。

1 <Query>  
2 <Where>  
3   <Eq>  
4    <FieldRef Name="ProjectID" />  
5    <Value Type="Lookup">My Test Project 1</Value>  
6   </Eq>  
7 </Where>  
8 </Query>

Value中只需要填写外键所对应的名称,而不用填写外键所对应的id。如果只知道id而不知道名称则可以使用下面的CAML。

1 <Query>  
2     <Where>  
3     <Eq>  
4         <FieldRef Name="ProjectID" LookupId="TRUE" />  
5         <Value Type="Text">3</Value>  
6     </Eq>  
7     </Where>  
8 </Query>

3. Lists.GetListItems()方法中的参数。

对于该方法中参数的详解,读者可以参考MSDN:

http://msdn.microsoft.com/zh-cn/library/websvclists.lists.getlistitems.aspx

这里对参数的几点用法做一些说明:

listName 要查询的List的名称,也可以为List的GUID,不能为空。
viewName 一般都为空。
query 标准CAML查询语句,可以为空,<Query></Query>
viewFields 要查询的字段,可以为空,<ViewFields></ViewFields>
rowLimit 返回的记录条数,默认为100,如果不需要限制,将值设为0 。
queryOptions 查询选项设置,所涉及到的选项比较多,可以参考MSDN。 
http://msdn.microsoft.com/zh-cn/library/websvclists.lists.getlistitems.aspx 
如果要查询List中Folder下的文档,则必须添加递归选项。 
<QueryOptions> 
   <ViewAttributes Scope="Recursive" /> 
</QueryOptions>
webID 可选参数。具体用法查看MSDN。

List的GUID可以通过调用Lists.GetListAndView()方法,在返回的报文中获取到。

http://msdn.microsoft.com/zh-cn/library/websvclists.lists.getlistandview.aspx

4. 搜集到的List中字段的属性,包括字段的Type。

ID The ID is a globally unique identifier (GUID) which you should generate for each field. This ID will be used in lists when referencing the site column
Type The type indicates the data type of the column and can be of the any following:
AllDayEvent The all day event flag is used in calendar lists.
Attachments The URL of an attachment.
Boolean A boolean indicator with Yes/No.
Calculated Indicates that the column is a calculated column based on a expression.
Choice Indicates that the column is choice from a list of items
Computed Indicates the field's value is dependant on another field's value.
ContentTypeId A Content Type ID value.
Counter An internal unique ID's / counter for each item.
Currency A currency value (its format depends on the locale).
DateTime A Date and Time field.
File A file object when used in document libraries.
GridChoice A rating scale as used in surveys
Guid A globally unique identifier.
Integer An integer number field.
Lookup The field is a lookup which is a choice, however the choice is from another list.
LookupMulti A lookup field, however multiple selections are allowed.
ModStat An approval status.
MultiChoice A choice field, however multiple selections are allowed
Note Multiple lines of text which can be plain or formatted.
Number A numerical field which allows decimal places.
PageSeparator A page separator field, for surveys.
Recurrence An indicator that identifies the field as a reoccurring calendar event.
Text A single line of text
ThreadIndex The ID of a discussion thread.
Threading Indicates the field supports threading (in discussions).
URL A Unified Resource Locator (URL) is stored.
User A person or group.
UserMulti A person or group, however multiple people or groups can be selected.
WorkflowEventType Contains the type of workflow history event (used in workflow history list).
WorkflowStatus The status of a workflow is stored.
Title The name of the field as displayed in the user interface.  This title may be set using a resource file.
Name (optional) The name of the field which should be guaranteed to never change.  The default is the Title with spaces and invalid characters removed.
StaticName (optional) The logical name of the field which is similar to Name, however this can be programmatically changed.
DisplayName (optional) See title.
Description (optional) A description of the field which will be displayed in front ends.  The description can be placed into a resource file.
Required (optional) Indicates whether or not the field is mandatory. The default is FALSE.
MaxLength (optional) The maximum number of characters allowed.
Hidden (optional) Indicates that the field should be hidden from the interface. If TRUE, this field will not be shown on views or forms. The default is FALSE.
Readonly (optional) The field should be read-only and can be displayed and not edited.  The default is FALSE.
ShowInDisplayForm (optional) Indicates whether the field should be shown on a display form. The default is TRUE.
ShowInEditForm (optional) Indicates whether the field should be shown on an edit form. The default is TRUE.
ShowInListSettings (optional) Indicates whether the field should be shown in the list settings screen. The default is TRUE.
ShowInNewForm (optional) Indicates whether the field should be shown on a New form. The default is TRUE.
ShowInVersionHistory (optional) Indicates whether the field should be shown in the version history of an item. The default is TRUE.
ShowInViewForms (optional) Indicates whether the field should be shown on a view form. The default is TRUE.
Group (optional) A group name allowing you to group fields together.

5. Customer List中的列名变化?

在Customer List中创建一个新列时,Sharepoint同时给它赋予了内部名称(FieldInternalName)和外部名称(FieldName),初始状态下内部名称和外部名称是相同的,当我们修改了List的列名时,外部名称被修改了,而内部名称则不变,为了防止在使用时出现找不到列的错误,必须在CAML中使用内部名称作为列名。可以借助CAML工具查找列的内部名称,也可以在List的新建记录页面中查看源代码,搜索显示的列名,找到类似于下面的代码段,FieldInternalName的值即为该列的内部名称。

<!-- FieldName="Area" 
    FieldInternalName="Title" 
    FieldType="SPFieldText" 
-->

6. 两个小工具,用于检测或生成CAML,对List的管理和查看报文的具体信息。实际项目应用中会很有用哦:)

U2U Caml Query Builder 2007 v3.1.0.0 (windows version)

Sharepoint Manager 2007

CAML的使用过程中还是会遇到很多问题的,以后遇到再逐渐补上吧!

本文转自Jaxu博客园博客,原文链接:http://www.cnblogs.com/jaxu/archive/2009/03/23/1419717.html,如需转载请自行联系原作者

对CAML查询语句的几点小记相关推荐

  1. 用LINQ结合CAML查询 Sharepoint 数据库内容

    直接用CAML语句查询Sharepoint有时候条件多比较麻烦,所以想到先用CAML查询出来一个对象,然后用LINQ来对对象再次操作 例如,先取一个SPLIST对象 ,然后用CAML对LIST查询操作 ...

  2. mysql查询第二个字母为a_MSSQL_关于SQL Server查询语句的使用,一.查询第二个字母是t或者a的 - phpStudy...

    关于SQL Server查询语句的使用 一.查询第二个字母是t或者a的雇员的全部信息 select * from employees where firstname like '_[t,a]%' 注意 ...

  3. mysql查询语句 变量_mysql查询语句中用户变量的使用

    先上代码吧 SELECT `notice`.`id` , `notice`.`fid` , `notice`.`has_read` , `notice`.`notice_time` , `notice ...

  4. groovy怎样从sql语句中截取表名_SQL常用的基础查询语句

    数据分析过程中,我们经常可以看到提数的SQL语句,了解SQL常用的基础查询语句,是检验提数逻辑是否正确的途径之一,并且也能更方便使用SMART BI数据分析工具.今天就让小编带大家走进SQL基础查询的 ...

  5. Oracle中分页查询语句

    Oracle分页查询语句使我们最常用的语句之一,下面就为您介绍的Oracle分页查询语句的用法,如果您对此方面感兴趣的话,不妨一看. Oracle分页查询语句基本上可以按照本文给出的格式来进行套用. ...

  6. hibernate中的hql查询语句list查询所有与iterate查询所有的区别

    hibernate中的hql查询语句list查询所有与iterate查询所有的区别 list查询所有: 01,会立即产生一条select语句1select查询出来的所有语句都会被session管理, ...

  7. SQL查询语句 select 详解

    查询select: 1.单表查询 2.多表查询 3.嵌套查询分类 1)单表查询 2)多表查询 A.连接查询 B.子查询 ①一般子查询 ②相关子查询*************************** ...

  8. oracle 判断11位数字,45个非常有用的 Oracle 查询语句小结

    日期/时间 相关查询 1.获取当前月份的第一天 运行这个命令能快速返回当前月份的第一天.你可以用任何的日期值替换 "SYSDATE"来指定查询的日期. SELECT TRUNC ( ...

  9. .Net+SQL Server企业应用性能优化笔记3——SQL查询语句

    在上一篇文章中我们使用了几种方法来确定瓶颈,找到瓶颈,下面再回顾一下: LoadRunner压力测试+Windows计数器,这种方法主要是找出大概的性能问题是在哪台服务器,主要是哪个资源紧张. ANT ...

最新文章

  1. k3应付系统初始化应付票据_在家工作时应付无尽干扰的真实感觉
  2. java使用HttpClient传输json格式的参数
  3. 手机游戏深化、改革。
  4. Android中配置JDK和SDK的环境变量
  5. Github标星66.6k+:常见数据结构与算法的Python实现
  6. CF176E Archaeology(set用法提示)
  7. CSS实现垂直居中的方法
  8. 2种造成sqlserver自增列不连续的原因
  9. Vue学习笔记之16-tarbar地开发思路
  10. 花瓣网爬虫Python
  11. 嵌入式linux 电容触摸屏驱动框架
  12. 201671010426 孙锦喆 实验二词频统计软件项目报告
  13. imap接收邮件服务器,配置 Outlook 从 IMAP 服务器接收邮件
  14. 学python-当当发布2020程序员新态:左手Python,右手机器学习
  15. ensp报错AR40,无法修改IP地址解决办法。
  16. 【SpringBoot进阶】阿里云短信发送配置
  17. 解决桌面图标无法拖动之绝招
  18. web端动效 lottie-web 使用
  19. PHP弹出对话框的方法
  20. BRD、MRD 和 PRD 之间的区别--学习记录

热门文章

  1. jsp页面textarea中换行替换问题
  2. iOS中常见的内存问题
  3. 使用OpenLDAP作为身份验证源
  4. 从 RequireJS 到 SeaJS(2)
  5. C/S构架和B/S架构的比较
  6. Windows、Linux系统安装JDK配置Java环境变量
  7. android注解的作用,Android 用注解来提升代码质量
  8. 网页登录接口php,thinkphp-登入接口示例
  9. myemployees库的四张表介绍
  10. 初识Docker-Docker的安装