I often find that I need to traverse the site collections in Sharepoint in search of a specific subsite. Often I do not have access to the full url, nor the sites that lead up to the subsite I am looking for.

Several sites will list code similar to this:

public static SPWeb findWeb(SPSite site, string name)
{
return (findWeb(site.AllWebs, name));
}

public static SPWeb findWeb(SPWebCollection webs, string name)
{
foreach (SPWeb myweb in webs)
{
SPWeb result = findWeb(myweb, name);
if (result != null)
{
return result;
}
}
return null;
}

Basically a recursive traversel of the site collection, looking for a specific name of a site.

In a previous post I outlined setting up a search scope and using the wonderful search feature of Sharepoint to acomplish the same task more efficiently.

Another appraoch, if you dont want to go through the trouble of a search scope, and you will be searching the site tree more than once is to parse out the result of the SPSite function AllWebs.

It returns a SPWebCollection object, which has a great property called Names. Names will give you a list of all the urls for all the sites.

I like to parse this,  take the name name of the deepest subsite, and the url, to populate a Dictionary that I can cache between searches.

You can use the SPSite objects  MakeFullUrl to retrieve the full Url of the subsite your inspecting.  

SPWebCollection col = site.AllWebs;

string[] urls = col.Names;
foreach (string url in urls)
{
string name = getDeepestSiteName(url);
if (name != null)
{
if (!allSites.ContainsKey(name))
{
allSites.Add(name, site.MakeFullUrl(url));
}
}
}