Thursday, October 3, 2013

Programmatically create sub-site AND validate if desired name exists

Hey,


Just see this Console Application:-




//Created on Console App..
SPSite osite = new SPSite(@"http://xyz:portNumber/");
bool siteExists = false;
//osite.AllWebs.Names requires Elevated Privileges
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//Names contains server Relative Urls not the Name(Title)
List<string> webServerRelUrls = osite.AllWebs.Names.ToList<string>();

foreach (string servUrl in webServerRelUrls)
{
string siteTitle = osite.AllWebs[servUrl].Title;

//Now it will compare the title with user's entered Name
if (siteTitle ==[/*stringwebNamfromInputTB*/])
{
siteExists = true;
//Do redirect to new page

break;

}

}

});

Mark HelpFul if works..



To be or Not to Be..The question is this only......



No comments:

Post a Comment