This is the exact code that I have:
[WebMethod]
public string AddSite(string collection, string url, string title, string description, string template) {
try {
SPSite siteCollection = new SPSite(collection);
SPWeb site = siteCollection.AllWebs[""];
SPWebCollection subSites = site.Webs;
SPWeb newWeb = subSites.Add(url, title, description, 1033, template, false, false);
return newWeb.Url.ToString();
} catch (Microsoft.SharePoint.SPException ee) {
ww.return ee.Message + "::" + ee.Source;
} catch (System.Exception ee) {
return ee.Message + "::" + ee.Source;
}
}
I should probably clarify the exception. No exception actually occurs when I execute the line SPSite siteCollection = new SPSite(collection). However, when I inspect the properties of the siteCollection object here is an example of what I see in the QuickWatch window:
siteCollection.Owner = 'siteCollection.Owner' threw an exception of type 'Microsoft.SharePoint.SPException'
siteCollection.Owner.base.Message = There is no Web named "/sites/clients".
On another property:
siteCollection.AllWebs.Count = 'siteCollection.AllWebs.Count' threw an exception of type 'Microsoft.SharePoint.SPException'
siteCollection.AllWebs.Count.base.Message = "Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))"
When I access another site that isn't using the host headers I get those properties filled in with values.