Search code examples
sharepointsharepoint-2007windows-sharepoint-serviceswss-3.0

Is there built-in method to tell if specific URL belongs to this SPWeb or other SPWeb?


I have a list of urls (content type usage url's). Now, content types are deployed across web's. I need to loop those content types and do some actions in each list, but opening new SPWeb instance every loop is too resource intensive.

Is there built-in method to tell me if this URL belongs to certain SPWeb object?

Example:

SPWeb's may be

With content type usage links like:

  • /web2/Pages
  • /web2/Lists/Tasks
  • /web2/Lists/Documents
  • /web2/subweb1/Lists/Tasks
  • ...

As you can see, for first 3 usages i don't need to open up new SPWeb


Solution

  • Just a guess, but maybe it's worth trying SPWeb.GetList(serverRelativeUrl) on the SPWeb instanes you already have and, if none matches, then create a new SPWeb?

    Update: another idea. Assuming that all the SPWebs live in the same SPSite, you might as well use this particular overload of SPSite.OpenWeb() (and set the requestExactUrl flag to false). This will return you the SPWeb object you need. Internally, the opened SPWeb objects are reused (which you can see in SPWeb.SPWebConstructor method in Reflector), so this won't hit performance too much. wrong, the SPweb objects are just stored in a list, not reused.