i was created event receiver to updated column value and create sub site from custom site template
the event call more than once . code
publicoverridevoid ItemUpdated(SPItemEventProperties properties)
{
this.EventFiringEnabled = false;
SPListItem thisItem = properties.ListItem;
if (properties.ListTitle == "ProjectsList")
{
string PMOFldName = properties.List.Fields["PMO"].InternalName;
if (properties.Web.CurrentUser.Name.Contains((string)thisItem[PMOFldName]))
return;
// check is project created column in projects list "IsProjectCreated".
bool _IsProjectCreated = false;
string _IsCreatedFldName = properties.List.Fields["IsProjectCreated"].InternalName;
_IsProjectCreated = (bool)thisItem[_IsCreatedFldName];
if (_IsProjectCreated)
return;
// get the initiative url .
string _Initiativefldname = properties.List.Fields["initiative"].InternalName;
SPFieldLookupValue _InitiativefldValue = newSPFieldLookupValue((string)thisItem[_Initiativefldname]);//(SPFieldLookupValue)thisItem[fldname];
string InitiativeURL = string.Empty;
if (!String.IsNullOrEmpty(_InitiativefldValue.LookupValue))
{
SPQuery qry = newSPQuery();
qry.Query ="<Where><Contains><FieldRef Name='Title'/><Value Type='Text'>"+ _InitiativefldValue.LookupValue +"</Value></Contains></Where>";
SPListItemCollection listItemColl = properties.Web.Lists["MoFA-ITC-Initiatives"].GetItems(qry); // in this line the code return to first line in method.
InitiativeURL = listItemColl[0]["URL"].ToString();
}
string _ProjectCodeFld = properties.List.Fields["ProjectCode"].InternalName;
string _ProjectCodeValue =(string)thisItem[_ProjectCodeFld];
if (!String.IsNullOrEmpty(_ProjectCodeValue))
{
using (SPSite site = newSPSite("http://moss:2010"))
{
using (SPWeb parentWeb = site.OpenWeb())
{
uint webLcid = parentWeb.Language; // also here return to the first line of code
SPWeb newWeb = site.AllWebs.Add(InitiativeURL+_ProjectCodeValue,_ProjectCodeValue,"Site created temp",webLcid,"{8B2DC134-5AFD-47EE-8E01-A7CCB4698A3F}#TestTMP1",false, false); // when call this method it return error it is already in use .
if (newWeb != null)
{
newWeb.Navigation.UseShared = true;
SPNavigationNode node = newSPNavigationNode(newWeb.Title, newWeb.ServerRelativeUrl);
// Find out if the parent inherits links.
bool parentInheritsTopNav = newWeb.ParentWeb.Navigation.UseShared;
if (parentInheritsTopNav)
{
// Add the link to the top link bar on the root web.
site.RootWeb.Navigation.TopNavigationBar.AddAsLast(node);
}
else
{
// Add the link to the top link bar on the parent web.
newWeb.ParentWeb.Navigation.TopNavigationBar.AddAsLast(node);
}
newWeb.Dispose();
}
}
}
// update project created field.
thisItem[_IsCreatedFldName] = true;
thisItem.Update();
}
}
this.EventFiringEnabled = true;
}
can any one help me ?
thanks in advence