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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.