SPListItemCollection.GetDataTable() 不返回所有列?
我在使用 GetDataTable() 方法时遇到了问题。我正在尝试返回结果中的默认 SharePoint 列“FileRef”以供使用。我将它包含在我的 SPQuery.ViewFields
查询中:
<Where><IsNotNull><FieldRef Name='FileRef'/></IsNotNull></Where>
ViewFields:
<FieldRef Name='Title' /><FieldRef Name='Category' /><FieldRef Name='FileRef' /><FieldRef Name='ID' /><FieldRef Name='Created' />
我什至可以看到它在 items.XML 中返回,但是当我调用 GetDataTable() 时,它没有放入数据表中。
SPListItemCollection items = list.GetItems(spq);
dtItems = items.GetDataTable();
为什么 GetDataTable 无法正常工作?我必须编写自己的转换方法吗?
I ran into an issue when using the GetDataTable() method. I'm trying to return the default SharePoint column "FileRef" in my results to use. I include it in my SPQuery.ViewFields
Query:
<Where><IsNotNull><FieldRef Name='FileRef'/></IsNotNull></Where>
ViewFields:
<FieldRef Name='Title' /><FieldRef Name='Category' /><FieldRef Name='FileRef' /><FieldRef Name='ID' /><FieldRef Name='Created' />
I can even see it returned in the items.XML but when I call GetDataTable() it is not put in the datatable.
SPListItemCollection items = list.GetItems(spq);
dtItems = items.GetDataTable();
Why isn't GetDataTable working correctly? Am I going to have to write my own conversion method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用以下代码:改进SharePoint的SPListItemCollection GetDataTable(),让我们获取我需要的所有字段
You can use this code:Improving SharePoint's SPListItemCollection GetDataTable(), let's get all the fields I need
我推荐您一个更好的解决方案
由于 SPListItemCollection 具有存储所有项目数据的 Xml 属性,您可以使用 此 XSLT 以普通 XML 格式获取数据,然后从 XML 创建 DataSet。
这个想法可以转换为方便的扩展功能:
顺便说一句,使用此方法,如果需要,您将获得文件附件 URL (
SPQuery.IncludeAttachmentUrls = true
),而不仅仅是 TRUE/FALSE 值,因为您将通过使用 前面提到的方法。I'd recommend you a better solution
As SPListItemCollection has Xml proeprty that stores all item data, you can use this XSLT to get data in normal XML format and then create DataSet from XML.
This Idea can be converted to handy extension function:
By the way, using this method, you will get, if needed, file attachment URL's (
SPQuery.IncludeAttachmentUrls = true
) not just TRUE/FALSE values as you would get it by using previously mentioned method.关于 Janis 的回答 - 我会删除在 ows_ 上执行子字符串的位并尝试删除它,只需使用:-
因为 SP2010 现在包含 ETag 等不包含“ows_”的字段,并且解决方案失败。否则非常好的解决方案。
Regarding Janis' answer - I'd remove the bits that do a substring on the ows_ and attempt to remove it, just use:-
because SP2010 now includes fields such as ETag which don't being with "ows_" and the solution fails. Very good solution otherwise.