SharePoint 2013 图文开发系列之代码定义列表
2013-12-06 23:41
453 查看
在SharePoint的开发中,用Visual Studio自定义列表是经常会用到的,因为很多时候,我们并不会手动创建列表,而手动创建列表在测试服务器和正式机之间同步字段,也很麻烦,所以我们经常用代码来定义列表或者文档库。
尤其在工作流的开发中,我们经常会用到代码定义任务列表,或者历史记录列表,用来存储我们需要存储的相关数据。而在Visual Studio 2013中,定义列表也提供了模板,通过模板创建,我们很容易就可以定义需要的列表了。
下面,让我们简单学习下,如何使用VS定义自定义列表。
1、跟之前一样,创建SharePoint 2013空项目,如下图:
View Code
12、部署定义的列表,在网站中打开,如下图:
![](http://images.cnitblog.com/blog/256729/201312/06194535-7955f1dc83bb4ba6825001a635ee17d7.png)
13、新建项目,可以看到我们添加的栏,查阅项没有关联,其他栏都正常,如下图:
![](http://images.cnitblog.com/blog/256729/201312/06194539-8917bf9e291644e9a5d6d53a5c76c19a.png)
14、修改Schema.xml中查阅项Field,添加下面两项,分别是查阅项关联的List和Field;
15、重新部署,如下图,可以看到查阅项正常了,OK!
![](http://images.cnitblog.com/blog/256729/201312/06194540-461d9f199dcc47a8a01266cec5f70737.png)
总 结
简单的用VS定义列表,就如上面介绍的,当然可能需要复杂的字段,我们无从知道字段的Field怎么定义,我们可以先手动创建一个类似字段,用SharePoint Manager 2013查看下字段的Xml,参考来定义我们的字段。
要说的就这么多了,很简单的一个例子,希望对初学者有所帮助,也希望高手指教错误,不吝赐教。
尤其在工作流的开发中,我们经常会用到代码定义任务列表,或者历史记录列表,用来存储我们需要存储的相关数据。而在Visual Studio 2013中,定义列表也提供了模板,通过模板创建,我们很容易就可以定义需要的列表了。
下面,让我们简单学习下,如何使用VS定义自定义列表。
1、跟之前一样,创建SharePoint 2013空项目,如下图:
<?xml version="1.0" encoding="utf-8"?> <List xmlns:ows="Microsoft SharePoint" Title="CustomList" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/CustomList" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/"> <MetaData> <ContentTypes> <ContentType ID="0x0100bdd9136fd8a7452dbadcdabda53becf7" Name="ListFieldsContentType"><FieldRefs><FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" /><FieldRef ID="{8c29daea-1ef8-43df-aa4d-00a4ad305e28}" Name="test" /><FieldRef ID="{b028b5c5-e3ed-4ca1-a5a5-a0260f41a5c8}" Name="_x67e5__x9605__x9879_" /><FieldRef ID="{b2a9e09b-9b62-4df4-a370-36b3869cb308}" Name="MyAuthor" /></FieldRefs></ContentType><ContentTypeRef ID="0x01"> <Folder TargetName="Item" /> </ContentTypeRef><ContentTypeRef ID="0x0120" /></ContentTypes> <Fields> <Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" DisplayName="$Resources:core,Title;" Required="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Title" MaxLength="255" /><Field Name="test" ID="{8c29daea-1ef8-43df-aa4d-00a4ad305e28}" DisplayName="内容" Type="Note" Required="FALSE" /><Field Name="_x67e5__x9605__x9879_" ID="{b028b5c5-e3ed-4ca1-a5a5-a0260f41a5c8}" List="{e22aa897-66d4-41fb-99b7-77acce6c10f6}" ShowField="Title" DisplayName="查阅项" Type="Lookup" /><Field Name="MyAuthor" ID="{b2a9e09b-9b62-4df4-a370-36b3869cb308}" DisplayName="作者" Type="User" /></Fields> <Views> <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE"> <Toolbar Type="Standard" /> <XslLink Default="TRUE">main.xsl</XslLink> <RowLimit Paged="TRUE">30</RowLimit> <ViewFields> <FieldRef Name="LinkTitleNoMenu"></FieldRef></ViewFields> <Query> <OrderBy> <FieldRef Name="Modified" Ascending="FALSE"></FieldRef></OrderBy> </Query> <ParameterBindings> <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" /> <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" /> <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" /> </ParameterBindings> </View><View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/15/images/generic.png?rev=23" Url="AllItems.aspx"> <Toolbar Type="Standard" /> <XslLink Default="TRUE">main.xsl</XslLink> <JSLink>clienttemplates.js</JSLink> <RowLimit Paged="TRUE">30</RowLimit> <ViewFields> <FieldRef Name="LinkTitle"></FieldRef><FieldRef Name="test" /><FieldRef Name="_x67e5__x9605__x9879_" /><FieldRef Name="MyAuthor" /></ViewFields> <Query> <OrderBy> <FieldRef Name="ID"></FieldRef></OrderBy> </Query> <ParameterBindings> <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" /> <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" /> </ParameterBindings> </View></Views> <Forms> <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /> </Forms> </MetaData> </List>
View Code
12、部署定义的列表,在网站中打开,如下图:
![](http://images.cnitblog.com/blog/256729/201312/06194535-7955f1dc83bb4ba6825001a635ee17d7.png)
13、新建项目,可以看到我们添加的栏,查阅项没有关联,其他栏都正常,如下图:
![](http://images.cnitblog.com/blog/256729/201312/06194539-8917bf9e291644e9a5d6d53a5c76c19a.png)
14、修改Schema.xml中查阅项Field,添加下面两项,分别是查阅项关联的List和Field;
List="{e22aa897-66d4-41fb-99b7-77acce6c10f6}" ShowField="Title"
15、重新部署,如下图,可以看到查阅项正常了,OK!
![](http://images.cnitblog.com/blog/256729/201312/06194540-461d9f199dcc47a8a01266cec5f70737.png)
总 结
简单的用VS定义列表,就如上面介绍的,当然可能需要复杂的字段,我们无从知道字段的Field怎么定义,我们可以先手动创建一个类似字段,用SharePoint Manager 2013查看下字段的Xml,参考来定义我们的字段。
要说的就这么多了,很简单的一个例子,希望对初学者有所帮助,也希望高手指教错误,不吝赐教。
相关文章推荐
- SharePoint 2013 图文开发系列之代码定义列表
- SharePoint 2013 图文开发系列之代码定义列表
- SharePoint 2013 图文开发系列之代码定义列表
- SharePoint 2013 图文开发系列之列表定义高级篇
- SharePoint 2013 图文开发系列之列表定义高级篇
- SharePoint 2013 图文开发系列之定义站点模板
- SharePoint 2013 图文开发系列之定义站点模板
- SharePoint 2013 图文开发系列之定义站点模板
- SharePoint 2013 图文开发系列之定义站点模板
- SharePoint 2013 图文开发系列之Visual Studio 创建母版页
- SharePoint 2013 图文开发系列之计时器任务
- SharePoint 2013 图文开发系列之自定义字段
- SharePoint 2013 图文开发系列之Visual Studio 创建母版页
- SharePoint 2013 图文开发系列之事件接收器
- SharePoint 2013 图文开发系列之InfoPath入门
- SharePoint 2013 图文开发系列之Visual Studio 创建母版页
- SharePoint 2013 图文开发系列之网站栏
- SharePoint 2013 图文开发系列之自定义字段
- SharePoint 2013 图文开发系列之Visual Studio 创建母版页
- SharePoint 2013 图文开发系列之创建内容类型