I need a fast way to ensure that site ID is correct. Instantiating SPSite seems to be quite expensive, so may be there are other options to do this.
|
Assuming there isn't a method somewhere within the SharePoint object model that does this in some super efficient way (yeah, I couldn't find one either), I've done some testing that seems to suggest that the best thing to do is to access the relevant SPWebApplication object and enumerate that object's Sites property. I created a quick test harness in the form of an application page with three buttons on it:
Once clicked, each button validates one or more site IDs using three different methods, each wrapped in an SPMonitoredScope instance:
Obviously, the last two test cases are only useful if you can access a valid Results Example developer dashboard output:
The following numbers are averages based on 5 clicks per button:
All that being said, I think it really depends on the nature of your comparison: how many IDs you're dealing with, how many site collections you're dealing with, etc. The win with the SPContext object is that it's already in memory, regardless of whether you're using it or not. If you're running through a collection of candidate site IDs within the context of a particular web application, my $0.02 is: grab the relevant SPWebApplication object and use a concise LINQ query to vet each ID:
Disclaimer: These tests were performed on a development farm with three web applications and only three site collections (one per web application). Windows Server 2008 R2, SharePoint Server 2010 (August 2011 CU) YMMV |
|||
|

