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!

  • 相关阅读:
    NVelocity实现违反了LSP法则,使我的一个低级错误排查了一个下午。
    ADO.NET EF 4中 query.Where().Where()和动态组合lambda实现组合查询的不同。
    发现blend4的一个导致崩溃的BUG!!!
    代码回滚:git reset、git checkout和git revert区别和联系
    精确获取函数运行时间,精确到微秒
    在github分支上上传空文件夹
    VS2010 LINK1123:failure during conversion to COFF:file invalid or corrupt
    同步github上fork出来的分支
    未能找到任何适合于指定的区域性或非特定区域性的资源。请确保在编译时已将“XXXXX.resources”正确嵌入或链接到程序集“XX”,或者确保所有需要的附属程序集都可加载并已进行了完全签名。
    决定以后把写博客转的主要平台转到cnblogs了
  • 原文地址:https://www.cnblogs.com/KingStar/p/1891749.html
Copyright © 2011-2022 走看看