views:

214

answers:

4

Given the SPList.ID and a site collection (or an SPWeb with subwebs), how do I quickly find the document library with the given ID?

I can recursively enumerate through all webs and perform a web.Lists[guid] on each one of them, but there might be thousands of subwebs in my case, and I'm looking for a realtime solution.

If there is no way to do this quickly, any other suggestions on how to uniquely identify a document library? I could store the full path (url), but the identification will be publicly visible and I don't feel very comfortable giving away our exact SharePoint document structure like that. Should I resort to maintaining a manual ID <-> library mapping in a separate list?

+1  A: 

MS does not support this :)... But take a look at this for giggles: http://weblogs.sqlteam.com/jhermiz/archive/2007/08/15/60288.aspx

JonH
Thanks, but we are trying to stay a certified gold partner, so that's not really an option... and we certainly didn't peek into the database ourselves to see if such a callback would be viable *nudge nudge, wink wink*. :-)
Paul-Jan
No problem, thought I'd try :).
JonH
+3  A: 

I vote for the manual ID -> URL pair matching in a top-level, well-known list that's visible only to the elevated privileges account.

Chris Farmer
+1  A: 

If you have MOSS Search available, then it might help, depending on the lag you have between these lists getting created and needing to search for them. You could probably map list id as a managed property and do a quick search for list objects with the id in question.

For lots of classes of problems it seems like search is the fastest way to rip through huge sets of data. In fact if this approach worked for you, you really wouldn't even need to know the site collection up front. Don't have access to any of my MOSS environments at the moment, so can't verify this will work though.

Sam Yates
+1  A: 

Since you are storing the ListID somewhere, you may also store the WebId. Lists are opened by the context SPWeb always, so if you go to:

http://toplevel/_layouts/ListGeneralSettings.aspx?ID={GUID1} // OK
http://toplevel/sub1/_layouts/ListGeneralSettings.aspx?ID={GUID1} // Wont Work (same Guid)

Having the WebId and ListId you can simply:

using(SPWeb subweb = (new SPSite("http://url")).OpenWeb(new Guid("{000...}")))
{
    SPList list = subweb.Lists.GetList(new Guid("{111...}"), true);
    // list logic
}
F.Aquino
Good suggestion! I have a bit of a practical problem in that the storage needed for a single GUID is already pushing it for this particular application (making the custom id -> url list more attractive, as I can generate my own simple id's there), but your make a solid point.
Paul-Jan
Oh, and in your example, won't that using statement only dispose the web (leaving the SPSite dangling)?
Paul-Jan
Yes Paul! Thanks for poiting it, my local test was using the context and I simply replace it with a 'url version'.
F.Aquino