博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WSS开发,搜索(SPQuery)时出现Invalid column name c2错误 (转载)
阅读量:5770 次
发布时间:2019-06-18

本文共 2391 字,大约阅读时间需要 7 分钟。

(转载自)

Invalid column name c2

SharePoint gives you this error when you try to search documents using the SPQuery object and you search by passing the document's

Name. SPQuery object uses the internal field names so it's important to pass correct internal name for the correct field to be

searched. By default, the "Name" field that is visible in the library has the internal name "LinkFilename" so when someone wants

to search a document in the library using the "Name" field, obviously he uses the "LinkFilename" to search the document but

strangely enough, it returns the following error:

"Invalid column name C2"

This error occurs in the sQL Server. SharePoint tries to search this field in the DB and returns an error when the field is not

found. I haven't checked whether this field actually exists in the DB or not but we get an error. There are two more "Name" fields

in the library. The internal names of the three "Name" fields are as following:

Name="LinkFilename" DisplayName="Name FieldType="Computed" -> default

Name="FileLeafRef" DisplayName="Name" FieldType="File"

Name="LinkFilenameNoMenu" DisplayName="Name" FieldType="Computed"

If you look at the definitions, you will notice that the FieldType of the two fields is "Computed" and for one field, it is

"File". By default, it is the first field that is shown in the library. It has the FieldType "Computed". To search the document in

the library using the "Name" field, you must use the second field that has the internal name "FileLeafRef". Although, this field

is not visible in the library by default but it will return the document in the search. It's FieldType is "File" and therefore,

you will have to pass the complete filename alongwith the extension in order for search to work and return the document. The third

"Name" field also errors out. It is not necessary to make this field visible in the library to make the search work.

Sample query:

SPQuery query = new SPQuery();

query.Query = "<Where><Eq><FieldRef Name='FileLeafRef'></FieldRef><Value Type='Text'>" + itemName + "</Value></Eq></Where>";
                           
SPListItemCollection listitems = list.GetItems(query);

"itemName" is the parameter that contains the file's name (passed from the interface or the calling function). It will be the

complete name (alongwith extension), for example, document1.doc.

 

转载于:https://www.cnblogs.com/llbofchina/archive/2008/06/03/1212838.html

你可能感兴趣的文章
CentOS7下安装python-pip
查看>>
认知计算 Cognitive Computing
查看>>
左手坐标系和右手坐标系 ZZ
查看>>
陀螺仪主要性能指标
查看>>
Java 架构师眼中的 HTTP 协议
查看>>
Linux 目录结构和常用命令
查看>>
Linux内存管理之mmap详解 (可用于android底层内存调试)
查看>>
利润表(年末)未分配利润公式备份
查看>>
Android开发中ViewStub的应用方法
查看>>
gen already exists but is not a source folder. Convert to a source folder or rename it 的解决办法...
查看>>
HDOJ-2069Coin Change(母函数加强)
查看>>
遍历Map的四种方法
查看>>
JAVA学习:maven开发环境快速搭建
查看>>
Altium Designer 小记
查看>>
【Linux高级驱动】I2C驱动框架分析
查看>>
赵雅智:js知识点汇总
查看>>
二维有序数组查找数字
查看>>
20个Linux服务器性能调优技巧
查看>>
多重影分身:一套代码如何生成多个小程序?
查看>>
Oracle将NetBeans交给了Apache基金会
查看>>