Sharepoint中FieldLink和Field之间的区别 [英] Difference between FieldLinks and Field in Sharepoint

查看:122
本文介绍了Sharepoint中FieldLink和Field之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将自定义内容类型从一个网站复制到另一个网站。我四处搜寻,发现了一些使用FieldLinks和Fields的示例。我有点迷惑要使用哪个,因为当我从源网络获取FieldLink时,我得到了3个字段;从Fields检索时,仅返回了2个字段...自定义字段丢失。我非常确定自从我通过界面添加字段以来,我已经添加了适当级别的字段。但是,当使用代码进行检索时...这些数字只是不加起来。

I'm in the middle of trying to copy a custom content type from one web to another. I've googled around and found some examples that use FieldLinks and Fields. I'm kind of lost as to which one to use, since when I get the FieldLinks from my source web, I get 3 fields; while retrieving from Fields only returned me 2 fields... the custom field is missing. I'm pretty darn sure that I've added the fields at the proper level since I did it via the interface. But when retrieving it using code... the numbers just don't add up.

因此,除了这个奇怪的问题之外,我还想知道FieldLinks之间的区别是什么和字段,以及在内容类型中(以编程方式)处理它们时,应该使用哪一个?

So besides from that strange problem, I want to know what is the difference between FieldLinks and Fields, and when dealing with them in Content Types (programmatically) which one should I use?

谢谢。

推荐答案

SPFields本身就是字段,而SPFieldLinks是对字段的引用。 这是一篇很好的文章,将详细解释事情。通常,在处理实际的内容类型定义时,使用SPFieldLinks更安全。但是,我将在此处给出一个简短的摘要。

SPFields are fields themselves, while SPFieldLinks are references to the fields. This is a good read that will explain things in detail. In general practice, it is safer to use SPFieldLinks when you are working on the actual content type definition. However, I'll give a quick summary here.

列表和站点包含带有字段数据的实际字段。另一方面,内容类型仅包含字段引用,该字段引用仅指向列表或网络中的相应字段。这有点令人困惑,因为内容类型同时具有SPFieldLinkCollection和SPFieldCollection。

Lists and Webs contain the actual fields with field data. A content type, on the other hand, only holds Field Reference, which simply points at the corresponding field in the list or web. This gets a bit confusing, because content types have both an SPFieldLinkCollection and an SPFieldCollection.

SPFieldLinkCollection用于内容类型的实际定义,是在将内容类型从一个网站复制到另一个网站时要使用的内容。 SPFieldLinks对应于XML Schema中内容类型的实际元素。

The SPFieldLinkCollection is used in the actual definition of the content type, and is what you would want to use in your situation of copying a content type from one web to another. SPFieldLinks correspond to the actual elements in the XML Schema for a content type.

相比之下,当您调用内容类型的SPFieldCollection并从中检索字段时,实际上发生的是该内容类型正在检查相应的字段引用,然后在列表/网络中查找以获取实际字段。基本上,以与查找工作相同的方式来考虑SPFieldCollection:没有查找值和查找源,它就毫无价值。

Comparatively, when you call on a content type's SPFieldCollection and retrieve a Field from it, what is actually happening is that the content type is checking the corresponding field reference, and then looking up in the list/web to get the actual field. Basically, think of the SPFieldCollection in the same way a lookup works: it is worthless without both the lookup value and the lookup source.

这篇关于Sharepoint中FieldLink和Field之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆