Checking if a SPWeb Exists
Posted by mundeep on December 19, 2007
Ran into a problem today where we were incorrectly trying to check if a web existed. We were trying:
private bool ChildWebExists(SPWeb parentWeb, string childWebName) { return null != parentWeb.Webs[childWebName]; }
however this always returns an actual SPWeb object, turns out the correct way is to check the Exists property of the returned object ie:
private bool ChildWebExists(SPWeb parentWeb, string childWebName) { using (SPweb childWeb = parentWeb.Webs[childWebName]) { return childWeb.Exists; } }
Checking if a SPFolder Exists « Point Deep said
[…] NB: Yes, this post is almost identical to my earlier one about checking if an SPWeb object exists. […]