In sharepoint how can i access all lists the site that have a certain name eg:
SPList list= web.Lists["MyList"]
will get it me at the root, but how can i access all of them that have that name in subsites also.
In sharepoint how can i access all lists the site that have a certain name eg:
SPList list= web.Lists["MyList"]
will get it me at the root, but how can i access all of them that have that name in subsites also.
You'll have to iterate through all the subsites of the site/site collection and see if that site has a list by the name of MyList in it. The SPWeb.webs property can get you all the sites underneath a site.
Edit
The reason for this is that sites in SharePoint are independent so you can't access resources in another site or site collection without first accessing that site or site collection.
So, to do a something like pulling up all tasks assigned to user, you would need to load every site in every site collection and check the task list to see if it had a task for that user. You can read this to get a better understanding of how Site Collections work. Sites function similarly, but are stored in the same contend database as the root site collection.
Edit 2
Or as pointed out in the comments on here, you can run an SPSiteDataQuery on a site collection so to iterate everything you'd just to have to iterate across site collections.
Iterating through SPWebs is not advisable, it would proably have to happen recursively (subsites of subsites of subsites etc.) which makes it very easy to introduce Dispose errors, i.e. forgetting to dispose an SPWeb object.
Do you need the lists so you can access the items in it? If they all have the same type of item in it I suggest you use the SPSiteDataQuery class, which takes a CAML query and does a query over all content in the site collection. You can use the resulting DataTable to display data
Edit: An alternative is FullTextSqlQuery (IF you are using MOSS, not WSS), which uses the SSP´s Search (indexed). By adding mapped properties in the SSP (meaning sitecolumns as a search property) you can talk to the SSP Search directly, the syntax resembles SQL