Open a SPWeb object to a load balanced farm

19 Mar

I was working on some quick utilities to address some upgrade bugs in Sharepoint 2007, and ran across some problems opening connections to a load balanced farm via the object model.

Here is a way that works, if you've got something better let me know!

           SPWebService myWebService = SPWebService .ContentService;

            SPWebApplication myWebApp = myWebService.WebApplications[ "web app name" ];

            SPSite mySite = myWebApp.Sites[BaseURL];

            SPWeb myWeb = mySite.OpenWeb();

Where 'web app name' is the name of the web app as you see it in IIS.  (e.g. "SPS Portal – 80")

Leave a Reply

Your email address will not be published. Required fields are marked *