Thursday, October 3, 2013

Programmatically create sub-site AND validate if desired name exists

Ok, I have modified my code, but am still not getting the desired results. Here is what I have done...


I had wrapped my entire code into this conditional statement which, for some reason, was failing. So it would skip the entire code block.



if (SPSite.Exists(new Uri(mysite.Url)) && mysite.ServerRelativeUrl.StartsWith("/" + childName + "/"))

After I removed it I could then step into my code, but where I don't understand is why my childWeb variable is returning null? Since there is a conditional if statement asking ... if(webs != null && Array.IndexOf(*webs, childWeb) >= 0) ... which fails because the childWeb variable is null it skips the code block and goes to the next block which asks if childWeb is null. Since it returns true it then runs the code trying to create a site. In this example I am using a site name that already exists, so I get an error.


Why is my variable childWeb returning a value of null when it should have the value of the parent site?


Here are some debugging screenshots ...


my "webs" string variable returns "null"



if "site.Webs.Names" is to return values ... why am I only getting partial values? There are 4 sub-sites under the current site so the count should be equal to 4 and the names of the sub-sites should populate the "Names" property. Why then are they empty?







No comments:

Post a Comment