Menu

#147 Correct way of iterating through SPWebApplication objects

Version 5.8
closed-fixed
nobody
5
2010-11-10
2010-11-06
Mike Lah
No

In the Sharepoint Interpreter, there are two different ways of iterating through the SPWebApplications on the server:

- SPWebApplicationProbe
if (SPWebService::ContentService != nullptr) {
SPWebApplicationCollection^ webApplicationCol = SPWebService::ContentService->WebApplications;
for each (SPWebApplication^ webApp in *webApplicationCol)

- SPCrawlRuleProbe
SPWebServiceCollection wsColl(SPFarm::Local);
for each (SPWebService ^ws in wsColl) {
for each (SPWebApplication ^app in ws->WebApplications) {

Do these return the same set of SPWebApplications?

Discussion

  • Michael Chisholm

    I would say they don't in general return the same web applications. One iterates over a collection of SPWebService's, and one gets a single SPWebService. Which is correct depends on how we should define the scope of the search and what SPWebService::ContentService actually returns. The MSDN docs for the latter say "Gets the Web service associated with the content application." which doesn't explain well enough for me.

     
  • Mike Lah

    Mike Lah - 2010-11-10

    The correct way is the method in SPCrawlRuleProbe. SPWebService::ContentService only returns the SPService that holds the content applications (notably omitting the Central Administration application, which is owned by SPWebService::AdministrationService).

    I have corrected the SPWebApplicationProbe.

     
  • Mike Lah

    Mike Lah - 2010-11-10
    • status: open --> closed-fixed
     

Log in to post a comment.