Your idea of mutualizing code is good IMO. I like your OfficeSearch
method.
About your const
s, you should indent them for better reading.
Regarding the code itself now, mind:
- Opening new
SPSite
/SPWeb
objects is costly. Consider opening only once and passing these objects as parameters (but don't forget to close them at the end). Or, if you're in a Web context (Web part, page...), you can simply rely on the contextual objects (SPContext.Current.Web
) that are already opened for you, and do not require disposing. Also, note they're under the identity of the current user. - Instead fof using:
SPList myList = currentWeb.Lists[Models.Sol.PB1.ListName];
and thus rely on name of the list, usecurrentWeb.GetList(SPUrlUtility.CombineUrl(currentWeb.Url, listWebRelativeUrl));