I need to developĀ a custom Web Part in C# to show the name and url ofĀ the list marching the specified type.
The idea being that the user will choose the ‘list type’ from a ‘checkbox list’ to select. The checkbox list contain ‘Event’, ‘Task’ and ‘Custom List’.
Since this is a checkbox list, the user will be able to select more than 1 list type. So for example, if the user selects ‘Event’ and ‘Custom List’, IĀ am supposed to show them the name of all the Custom & Event List’s that are in the site, regardless of whether the list’s contain any item. For each list I need to supply aĀ link (url) to the matching lists.
Any ideas on how to do this?
Thanks for the question. First and foremost I’d like to bring up the idea of not using C# for your webpart. Farm Solutions are no longer the “best practice” way to be building webparts in your SharePoint environment. For more information click hereĀ .
If you really need a webpart, I would look into the SharePoint-Add In Model and use JavaScript to do this. However, you should should use the REST APIs to do all of this work (whether in C# or JavaScript).
Please see the MSDN Rest APIĀ . In there you will see how to interact with the lists (the returned queries will have the template type).
Now, if you wish to go a different way… you would use SharePoint Search (Content Search Webpart (if you have licensing)). You could easily query ALL of the lists in your site using a simple REST Query using the Search API found here. You can find examples of using “Content_Class” to query your lists and by your templates here.