Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

WSS V2 Creating sub site

  Asked By: Dana    Date: Jul 27    Category: Sharepoint    Views: 2217

I am using the SharePoint object model to create sub-sites underneath
a site collection. Is it possible to do this if the WSS site is using
host headers? My initial test has given me an error stating that the
site collection couldn't be found.



6 Answers Found

Answer #1    Answered By: Cassidy Sharpe     Answered On: Jul 27

I only use host headers............

Answer #2    Answered By: Linda Mason     Answered On: Jul 27

I have created a top-level site  underneath a WSS site that is using host headers. However when I go to use the following code:

SPSite siteCollection = new SPSite(collection);

and the collection  is set to http://sites.server/sites/clients" target="_blank" rel="nofollow">http://sites.server/sites/clients I get the message saying "There is no Web named "/sites/clients". I used IE to navigate to http://sites.server/sites/clients" target="_blank" rel="nofollow">http://sites.server/sites/clients and the top-level web is there.

I created another collection under a different WSS site and I get no error  when the collection is http://server/sites/clients.

Any ideas?

Answer #3    Answered By: Hans Weiss     Answered On: Jul 27

Is this the exact message? There is no Web named "/sites/clients"

The reason that I ask is because you are trying to create  an SPSite
object when the error  occurs. That seems odd. How are you getting the
top-level site  from the siteColleciton object?

SPWeb site = siteCollection.RootWeb();

SPWeb site = siteCollection.OpenWeb("");

SPWeb site = siteCollection.AllWebs("");

Answer #4    Answered By: Alison West     Answered On: Jul 27

This is the exact code that I have:

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.

Answer #5    Answered By: Freddy Heath     Answered On: Jul 27

What if you change AllWebs[""] to RootWeb()?

Answer #6    Answered By: Joanna Dixon     Answered On: Jul 27

I tried to change it and I get the same problem. Would it not still fail because the line before that to obtain the siteCollection failed?

Didn't find what you were looking for? Find more on WSS V2 Creating sub site Or get search suggestion and latest updates.