SharePoint lists as data sources - how to manage

This is kind of a newbie question:

We have a web part with custom controls and an SP list as a data source.

For sites of different types, team sites, publishing portals, etc. speak. the path for the corresponding list will be different. for example: Team Site it would be http://<Server>/Lists/<List Name>

for a publishing portal with localization too http://<Server>/<Locale>/Lists/<List Name>

.

How do you control how the Web Part works regardless of where the list is placed in the site collection?

Please suggest.

+2


source to share


3 answers


On most websites, I have a configuration list at the root of the site collection. The list consists of a key / value pair. It is limited to admin access only and saves settings like this. Since this is just another SharePoint list, it is very easy to edit it.

Thus, the web part will execute SPQuery on the configuration list and look for a specific key (for example, "List Data Source Location"). The URL will be returned and can then be used as a data source. You do not need to set a key or URL for each web part instance, although you may need to implement a default that can be overridden.



(As an alternative, a better alternative to using your own config list if you need to store more complex data structures is SPConfigStore .)

+3


source


You must open a property in the web part that points to the URL of the list. You can then annotate this property so that SharePoint will automatically allow you to set the property in the Editor Zone. (IE right pane that appears when you edit a web part)

You can use the following attributes to influence how SP renders / stores a parameter:



  • personalized
  • WebBrowsable
  • WebDescription
  • WebDisplayName
  • Category
+3


source


Another way to solve your problem is to allow the Web Parts to go through all the sites in the site collection (SPWeb) and search there for the list you want.

If you access websites using the object model, it doesn't matter if the site is local or not. You can get all the lists of a website using its SPWeb.Lists property.

+1


source







All Articles