zoukankan      html  css  js  c++  java
  • How to create a custom list with custom views based upon a custom list definition

    Once I have got a customer request to create custom lists with custom views, not through custom code but through custom list definition.

     

    WOW it will be really a cool stuff to do!!!

     

    They already have a custom list definition and whenever they create a new list based upon that custom list definition it will create a list with a default view which was “All items”. But, they wanted some custom views has to be there by default whenever they create a new list based upon their custom list definition.

     

    If you want to know how we can create a custom list defintion please refer the below MSDN article:

    http://msdn.microsoft.com/en-us/library/ms466023.aspx

     

    Now we can see the funny development part…

     

    Here we can talk with a custom list definition by taking an eg: of custom list definition of “LinkList” and its definition will be there in the following location.

     

    Drive:\Program Files\Common Files\Microsoft Shared\web server extensions \12 \ TEMPLATE \ FEATURES \LinksList

     

    If you do the necessary changes after copying and renaming this folder your custom list definition for LinksList is ready. And once you activate the corresponding feature and create new list then you can see that it will show only a single view which will be “All items” by default.

     

    references:http://blogs.msdn.com/b/sowmyancs/archive/2008/06/14/how-to-create-a-custom-list-definitions-with-custom-views.aspx

     

    Now, we can see how we can add custom view definition to the schema.xml of our custom view. If we open the schema.xml file then you can see the following tags for the views. View with the BaseViewID=1 is the "All Items" view.

     

    <Views>

    <View BaseViewID="0" Type="HTML" OrderedView="TRUE">

    + <ViewHeader>

    + <HTML>

    - <![CDATA[ ……

      ]]>

      </HTML>

      </ViewEmpty>

    - <Query>

    - <OrderBy>

      <FieldRef Name="Order" Ascending="TRUE" />

      </OrderBy>

      </Query>

    - <ViewFields>

      <FieldRef Name="URL" Explicit="TRUE" />

      <FieldRef Name="URLNoMenu" />

      </ViewFields>

      <RowLimit>20</RowLimit>

      </View>

    <View BaseViewID="1" Type="HTML" OrderedView="TRUE" WebPartZoneID="Main" DisplayName="$Resources:core,All_Links;" DefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/links.png" Url="AllItems.aspx">

    …..

    </ View></ Views>

     

    Now our next task is creating a new view definition <View></ View> for our custom view.

     

    So now the question is, do I need to write all those definitions inside the schema.xml file L ?

    Ans :  yes ofcourse, but don’t worry we have an easy way to do it. J.

     

    Though the “easy way” is somewhat tricky it will reduce our task and it will not create any syntactical errors. In order to get a custom view definition, first you have to create a view from UI and then save your list as list template. From the list template you will get the new view’s definition.

     

    Here are the steps:

     

    1.      Create an instance of LinksList

          2.      Create custom view in the UI

    3.      Now save the list as List Template. 

        3.1    List settings à Permissions and Management à Save List as Template.

    4.      Download the List template from the List Template Gallery.

        4.1  Site Actions àSite Settings à Galleries à List templates.

          5.   Rename the list template file to .cab and open the manifest.xml file

          6.   From the manifest.xml we will get the View definition of our custom view. Just copy it and paste

                it in to the schema.xml.

     

    While doing the 6th step you have to remember some points. If you just cross check the custom view definition with the “All Items” view then we can see that some of the attributes were missing in the  custom view definition. One important attribute will be SetupPath. You can see it in the highlighted part of my custom view definition below.  SetupPath will take a page viewpage.aspx as its value , which is located physically in the following location.

     

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\Pages

     

    If you open this page then you can see a WebPartZone with ID “main”, this webpart zone will include the view pages once we creates it. Thus, WebPartZoneID and SetupPath attributes are mandatory while adding a custom view definition.

     

    Also, we can  specify new Url instead of AllItems.aspx like below and then it will show the list in this new Url.

     

    <!--My Custom View Start-->

    <View Name="{EAA1BF1B-C838-42CC-BA89-DEE69C1591E3}" WebPartZoneID="Main"  Type="HTML" DisplayName="sowmyanview" SetupPath="pages\viewpage.aspx" Url="sowmyan.aspx" Level="1" BaseViewID="2" ContentTypeID="0x" ImageUrl="/_layouts/images/generic.png">   

    </View>

    <!--My Custom View End-->

     

    If you didn’t do the above changes then while creating a new instance of your list you will get a "FileNotFoundException" exception. So you have to remember those important points in mind. After completing those modifications, we have to uninstall our custom fetaure or install it forcefully again. Now we can see our custom view whenever we create a new list!

  • 相关阅读:
    2019牛客暑期多校训练营(第二场)
    2019牛客暑期多校训练营(第一场)
    JOISC2014 挂饰("01"背包)
    UPC 2019年第二阶段我要变强个人训练赛第十六场
    UPC个人训练赛第十五场(AtCoder Grand Contest 031)
    Wannafly挑战赛15 C“出队”(约瑟夫环类问题)
    UVA 133“The Dole Queue”(循环报数处理技巧)
    洛谷P1169 [ZJOI2007]棋盘制作 悬线法 动态规划
    洛谷P1273 有线电视网 树上分组背包DP
    CF1097D Makoto and a Blackboard 质因数分解 DP
  • 原文地址:https://www.cnblogs.com/KingStar/p/1891749.html
Copyright © 2011-2022 走看看