在代码中检索SPSite集合的最佳方式
题
我有一个页面,用户将在文本框中输入数据,然后单击提交,它带来了URL在TextBox中包含此数据的所有站点集合,我是Currenlty进行LINQ查询,以便从中携带所有网站当前的Web应用程序在其中URL包含此文本框值,但我不确定这是最好的方法,我不确定这种方式是否与所有Spsite Disposale都很好,我不知道我是否应该处置这些物体与否。任何帮助吗?
解决方案
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/