Its a kind of newbie question:
We have a web part with user controls and a SP list as data source.
For different kind of sites say team sites, publishing portals etc the path for the respective list would be different. eg: Team Site it would be http://<Server>/Lists/<List Name> and for Publishing portal with Localization http://<Server>/<Locale>/Lists/<List Name>.
How do you manage the web part to be working no matter where the list is placed in the site collection?
Please suggest.
On most web sites I have a Configuration list in the root of the site collection. The list consists of key/value pairs. It is restricted to administrator access only and stores settings such as this. As it’s just another SharePoint list it’s very easy to edit.
So the web part would execute an SPQuery over the Configuration list and look for a particular key (e.g. “List Data Source Location”). The URL would be returned and can then be used as the data source. There is no need to set the key or URL on every instance of the web part, although you may like to implement a default that can be overridden.
(As an aside, a better alternative to using your own Configuration list if you need to store more complex data structures is SPConfigStore.)