如何让CAML表达式支持中文名的列

用Query的方式查询sharepoint列表,是效率比较高的一种方式,这就涉及到使用CAML语法的问题,个人感觉CAML语法写起来还是比较繁琐的,可以参考http://www.cnblogs.com/shanqian/archive/2007/08/17/859513.html

记得网络上还有有人写过CAML语法的工具。 幸好,项目中的需求没有太复杂的CAML语法嵌套,到目前为止都是手写,基本满足需求,不过会遇到一个问题,就是CAML语法不支持中文名称的列。其实,可以通过InternalName的方法解决。
示例代码如下: 以下是要查找任务列表中是否有制定分配对象、区域和报销人的任务,这些列都是中文名的,都必须通过InternalName来转换成全局名称。
SPSite siteCollection = new SPSite("http://192.168.30.6:1616");
            SPList listDes = siteCollection.RootWeb.Lists["任务"];
            SPMember oMember = workflowProperties.Web.AllUsers[System.Configuration.ConfigurationManager.AppSettings["ActiveDirectory"].ToString() + person];
            SPQuery query = new SPQuery();
            query.Query = "<Where><And>"
                + "<Eq><FieldRef Name='" + listDes.Fields["分配对象"].InternalName + "'/><Value Type='Text'>" + person + "</Value></Eq>"
                + "<And><Eq><FieldRef Name='" + listDes.Fields["区域"].InternalName + "'/><Value Type='Text'>费用计划</Value></Eq>"
                + "<Eq><FieldRef Name='" + listDes.Fields["报销人"].InternalName + "'/><Value Type='Text'>" + item["月份"].ToString() + "</Value></Eq></And>"
                + "</And></Where>";            SPListItemCollection listItems = listDes.GetItems(query);            foreach (SPListItem listItem in listItems)
            {
                return true;
            }
            return false; 其实,InternalName在sharepoint开发中很常用,基本不支持中文的地方,都可以考虑使用这个思路来解决。
posted @ 2008-12-01 11:36  浪漫稻草人  阅读(251)  评论(0)    收藏  举报