Best way of retrieving a collection of SPSite in code
Question
I have a page where the user will be entering a data in a textbox, and click submit, and it brings all site collections that url contains this data in textbox, I am currenlty doing a Linq query to bring all sites from the current web app where the url contains this textbox value, but I am not sure if this is the best way to do it, and I am not sure if this way deals well with all SPSite disposale, I don't know if I should dispose of these objects or not. Any help?
Solution
You will need to dispose the SPSite objects and write an extension method for that since it is in LINQ. However, you can also achieve your result using foreach
loops instead of LINQ.
See this for more information on using LINQ and SharePoint objects which need to be disposed like SPSite
and SPWeb
:
https://stackoverflow.com/questions/657095/using-linq-with-sharepoint-and-disposing-of-objects http://solutionizing.net/2009/01/05/linq-for-spwebcollection-revisited-assafeenumerable/