Not sure if it was me that prompted Neil’s post, but a question that came up earlier today was how to retrieve an SPWebApplication from its ID. Neil suggested trying to retrieve the generic SPPersistedObject by that ID, which eventually led me to SPFarm.GetObject(Guid).
SPFarm farm = SPFarm.Local; Guid webAppId = new Guid("e81de291-7205-42fe-8228-422c6bbed277"); SPWebApplication webApp = farm.GetObject(webAppId) as SPWebApplication; Debug.WriteLine(webApp);
Have I overlooked another method, or is this really the only way?
Bonus tip: Use
SPAdministrationWebApplication.Local to get the web app for Central Admin.