SharePoint Development - Custom Content Type using Visual Studio 2010 based SharePoint 2010
2014-05-23 15:59
567 查看
博客地址 http://blog.csdn.net/foxdave 本文所述均来自之前实际的项目模块
首先再论述一下SharePoint ContentType内容类型
SharePoint的列表和文档库可以储存不同类型的内容就叫做内容类型,比如文档库的文档,调查列表的调查等,都称作是内容类型。内容类型在网站范围内是可用的,不同的内容类型具有不同的内容和设置(如策略,关联的工作流等)。
通俗来讲,内容类型可以是文档,可以是文件夹,也可以是字段的集合。创建好后的内容类型可以与列表关联,体现在列表的新建项目上。没有凭空而来的内容类型,任何自定义内容类型都是基于现有类型创建的。SharePoint自有的内容类型可以通过访问网站设置->库->网站内容类型进行查看。更多的细节在此就不赘述了,下面进入正题。
打开Visual Studio,新建一个SharePoint空项目,添加一个内容类型,此时会弹出向导,询问基于哪个内容类型创建。这里我们创建一个最基本的,选择项目,点击完成。如下图所示
创建好之后可以看到如下ContentType定义文件(Elements.xml)
在定义文件中,如果我们想添加一个富文本字段,就做如下操作:
先声明一个Field节点
首先再论述一下SharePoint ContentType内容类型
SharePoint的列表和文档库可以储存不同类型的内容就叫做内容类型,比如文档库的文档,调查列表的调查等,都称作是内容类型。内容类型在网站范围内是可用的,不同的内容类型具有不同的内容和设置(如策略,关联的工作流等)。
通俗来讲,内容类型可以是文档,可以是文件夹,也可以是字段的集合。创建好后的内容类型可以与列表关联,体现在列表的新建项目上。没有凭空而来的内容类型,任何自定义内容类型都是基于现有类型创建的。SharePoint自有的内容类型可以通过访问网站设置->库->网站内容类型进行查看。更多的细节在此就不赘述了,下面进入正题。
打开Visual Studio,新建一个SharePoint空项目,添加一个内容类型,此时会弹出向导,询问基于哪个内容类型创建。这里我们创建一个最基本的,选择项目,点击完成。如下图所示
创建好之后可以看到如下ContentType定义文件(Elements.xml)
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <!-- 父内容类型: 项目 (0x01) --> <ContentType ID="0x0100aaeaadf3a9204fc38b69ae330f007f26" Name="SharePointProjectCT - ContentType1" Group="自定义内容类型" Description="我的内容类型" Inherits="TRUE" Version="0"> <FieldRefs> </FieldRefs> </ContentType> </Elements>其中有注释,表述该内容类型继承自项目,项目内容类型的ID为0x01。Visual Studio为我们自动生成了ContentType的基本定义,注意这里的ID,以0x01开头,这个不能改,因为内容类型的继承关系就是通过这个ID体现的。更多关于内容类型的ID的说明请戳这里,关于ContentType定义的属性说明请戳这里。
在定义文件中,如果我们想添加一个富文本字段,就做如下操作:
先声明一个Field节点
<Field ID="{FD0FFFC6-813E-4579-BCCF-797DE7724733}" Name="MyContent" Type="Note" RichText="TRUE" RichTextMode="Text" DisplayName="内容" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInNewForm="TRUE" Group="自定义字段" ></Field>然后在内容类型中引用这个Field,用FieldRef节点
<FieldRefs> <FieldRef ID="{FD0FFFC6-813E-4579-BCCF-797DE7724733}" Name="MyContent"/> </FieldRefs>完整的定义文件如下所示
<?xml version="1.0" encoding="utf-8"?>完成之后保存,部署。之后到SharePoint网站设置的内容类型里,可以看到我们刚才添加的内容类型了。
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field ID="{FD0FFFC6-813E-4579-BCCF-797DE7724733}" Name="MyContent" Type="Note" RichText="TRUE" RichTextMode="Text" DisplayName="内容" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInNewForm="TRUE" Group="自定义字段" ></Field>
<!-- 父内容类型: 项目 (0x01) -->
<ContentType ID="0x0100aaeaadf3a9204fc38b69ae330f007f26"
Name="SharePointProjectCT - ContentType1"
Group="自定义内容类型"
Description="我的内容类型"
Inherits="TRUE"
Version="0">
<FieldRefs> <FieldRef ID="{FD0FFFC6-813E-4579-BCCF-797DE7724733}" Name="MyContent"/> </FieldRefs>
</ContentType>
</Elements>
相关文章推荐
- SharePoint Development - Custom List using Visual Studio 2010 based SharePoint 2010
- SharePoint Development - Custom Field using Visual Studio 2010 based SharePoint 2010
- Deploy custom Css,Js files in SharePoint 2010 using visual studio 2010
- 转:Creating a SharePoint Visual Web Part using Visual Studio 2010
- sharepoint ECMA using a custom contentType to creating a list in SubSite
- Create custom Task List and Forms in SharePoint 2010 with Visual Studio 2012
- Developing SharePoint 2010 features using Visual Studio 2010
- Adding Custom Actions to the List Item Menu in SharePoint 2010 Using SharePoint Designer 2010[Sharepoint中添加自定义菜单]
- Upload a file to Sharepoint 2007 using webservices with a specific content type
- Create a Simple Custom Action Using Visual Studio 2010
- SharePoint 2010: Create a Custom Page Layout for a Publishing Site using SharePoint Designer
- add a custom action to a SharePoint list actions menu for a specific list or content type
- Change language of UI using custom control in SharePoint 2010
- Creating a SharePoint BCS .NET Connectivity Assembly to Crawl RSS Data in Visual Studio 2010
- Creating SharePoint 2010 Event Receivers in Visual Studio 2010
- Think in SharePoint 2010 OOTB Project: Site Columns & Site Content Type
- Creating and Using a New Content Type in SharePoint 2007(zhuan:http://www.sharepointproconnections.com/article/sharepoint-portal
- Creating SharePoint 2010 Event Receivers in Visual Studio 2010
- Think in SharePoint 2010 OOTB Project: Site Columns & Site Content Type
- Force stop and then start a full crawl on all content sources in a SharePoint 2010 farm using PowerShell(转)