Sharepoint 2010 - 使用服务器对象模型将标题、描述和关键字字段设为图片库中的必填字段
我正在创建一个 Sharepoint 功能,该功能有一个与之关联的事件接收器。在事件接收器中,我使用服务器端对象模型创建文档库和图片库。我还向这些新创建的文档和图片库添加了新的自定义列(大约 80 个)。现在我想修改默认情况下与图片库一起创建的“描述”、“关键字”和“标题”字段的属性。我想将这些字段设为必填字段。我该怎么做?我尝试设置 SPList.AllowContentTypes = true 并尝试更改这些字段的属性,但它不起作用(既不给出错误也不生成这些必填字段)。我还尝试访问内容类型并尝试使用 SPContentType.FieldsLinks["Column_name"].Required 和 SPContentType.Fields["Column_name"].Required 更改属性,但它给了我一个错误。有人还有其他建议吗?
I'm creating a Sharepoint feature, this feature has an event receiver associated to it. In the event receiver, I'm creating a Document Library and Picture Library using server-side object model. I'm also adding new custom columns (around 80) to these newly created document and picture library. Now I want to modify the properties of the Description, Keywords and Title fields that are by default created along with the picture library. I want to make these fields as Required fields. How do I do this? I tried to set SPList.AllowContentTypes = true and try to change the attributes of these fields, but it doesn't work (neither gives an error nor makes these required fields). I also tried to access the content types and try to change the attributes using SPContentType.FieldsLinks["Column_name"].Required and SPContentType.Fields["Column_name"].Required but it gives me an error. Does anyone have any other suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是答案......
Here is the answer....
您能告诉我们您在尝试使用字段链接时遇到的错误吗?因为这应该有效...我是这样做的:
can you tell us the error you got when trying to use the fieldlinks? Because this should work... I have done it like this:
这应该可以解决问题:
This should do the trick:
SPAllowContentTypes 不可设置。您可以尝试设置 ContentTypesEnabled。
我没有 2010 框可供测试,但如果 SPAllowContentTypes 返回 false 我认为您正在考虑将 14 配置单元 (TEMPLATE\FEATURES\PictureLibrary\PicLib) 中图片库的定义修改为得到你想要的。那里轻轻踩一下。
SPAllowContentTypes isn't settable. You might try setting ContentTypesEnabled instead.
I don't have a 2010 box to test against, but if SPAllowContentTypes returns false I think you're looking at modifying the definition of your picture library in the 14 hive (TEMPLATE\FEATURES\PictureLibrary\PicLib) to get what you're after. Tread lightly there.