locked
reference list definition feature in visual web part RRS feed

  • Question

  • Hi ,

    I want to  create a custom web part to display content from a custom list definition. Can anyone help me out in this.

    Thanks in advance.

    Friday, October 14, 2011 9:06 AM

Answers

  • When you create your ListDefinition in Visual Studio it will ask you if you want to provision an instance of that list.  You can click yes there, and it will generate the element definition for a list instance to be deployed.  If not, you can always do it yourself by providing a ListInstance element (http://msdn.microsoft.com/en-us/library/ms476062.aspx) in one of your modules.  Make sure the TemplateType attribute matches the ID of the ListTemplate element in your feature. (ListTemplate on msdn: http://msdn.microsoft.com/en-us/library/ms462947.aspx)

    Here's a walkthrough on MSDN to do all of it: http://msdn.microsoft.com/en-us/library/gg276355.aspx

    This allows you to set up what url the List gets created at, so it should be asy to use a convention in your web part code to always pull data from that list.  A better solution you might consider would be to allow the user that adds the web part to the page to select the list (or provide the url to the list) that the web part should care about.  Handle the scenario in your web part when the list doesn't exist to protect your farm from user's deleting the list out from under the web part. 

    Hope it helps.


    Jonathan Mast
    Senior SharePoint Consultant | SharePoint911: SharePoint Consulting
    Blog: www.jonathanpmast.com/blog
    Twitter: @jonathanpmast
    • Marked as answer by Zizhuoye Chen Thursday, October 20, 2011 1:42 AM
    Friday, October 14, 2011 1:19 PM

All replies

  • you mean that you want to show from list schema.xml ? or custom List ?

    Check this article , if you want to show information from custom list 

    http://deepakssolanki.over-blog.com/article-sharepoint-web-part-to-show-data-from-list-72132381.html


    Regards,
    Milan Chauhan
    Friday, October 14, 2011 10:40 AM
  • Hi Nishara,

    Which content do you want to display?. At the end of the day you just need to query the list to get the data.

    Have a look to my post, it will probably help you, go to Step 8 where I add the webpart, that will give you an idea. You can download the code as well.

    http://netsourcecode.blogspot.com/2011/09/how-to-create-simple-custom-site.html

    Regards


    Gabriel Renom - Business Systems Analyst - Pannone LLP - Blog: www.gabrielrenom.net

    Friday, October 14, 2011 10:47 AM
  • Hi

    let me be more brief about my requirement. I have created a list definition project which creates a custom list and visual web part project in vs2010. I want the web part  to display contents of custom list .I have tried displaying Share point list using custom web part. but since the custom list name is hard coded there , i wanted the list  to becreated through code. Is there any way to do t? I am new to share point.

    Friday, October 14, 2011 12:27 PM
  • When you create your ListDefinition in Visual Studio it will ask you if you want to provision an instance of that list.  You can click yes there, and it will generate the element definition for a list instance to be deployed.  If not, you can always do it yourself by providing a ListInstance element (http://msdn.microsoft.com/en-us/library/ms476062.aspx) in one of your modules.  Make sure the TemplateType attribute matches the ID of the ListTemplate element in your feature. (ListTemplate on msdn: http://msdn.microsoft.com/en-us/library/ms462947.aspx)

    Here's a walkthrough on MSDN to do all of it: http://msdn.microsoft.com/en-us/library/gg276355.aspx

    This allows you to set up what url the List gets created at, so it should be asy to use a convention in your web part code to always pull data from that list.  A better solution you might consider would be to allow the user that adds the web part to the page to select the list (or provide the url to the list) that the web part should care about.  Handle the scenario in your web part when the list doesn't exist to protect your farm from user's deleting the list out from under the web part. 

    Hope it helps.


    Jonathan Mast
    Senior SharePoint Consultant | SharePoint911: SharePoint Consulting
    Blog: www.jonathanpmast.com/blog
    Twitter: @jonathanpmast
    • Marked as answer by Zizhuoye Chen Thursday, October 20, 2011 1:42 AM
    Friday, October 14, 2011 1:19 PM
  • Thanks a lot guys. :)
    Monday, October 17, 2011 4:43 AM