12 May 2009

Creating Sub-Site on List item added using event Handler

Creating a Sub site when a new item is added in the list.
All that needs to be carried is create a event handler with overriding methods ItemAdded or Itemupdated.

<--Code-->
string Url = "http://Site_URL/sites/demo";
using (SPSite oSite = new SPSite(Url))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPList projectList = oWeb.Lists["MYCustomList"];
//foreach(SPListItem listItem in projectList)
//{

string projectName =properties.ListItem["Title"].ToString();
SPWebCollection collWebsites = oWeb.Webs;
oWeb.AllowUnsafeUpdates = true;
oWeb.Navigation.TopNavigationBar.Parent.IsVisible = true;
string strWebUrl = projectName;
string siteTitle = projectName;
string siteDescription = "Sub site created by code.";
collWebsites.Add(strWebUrl, siteTitle, siteDescription, 1033, "MyTeamSitetemplate.stp", true, false);

//}
}
}

No comments:

Post a Comment

Thanks for your valuable comments

Rate Now: