Quantcast
Channel: SharePoint 2010 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 17574

Event reciever ItemUpdated

$
0
0

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 


Viewing all articles
Browse latest Browse all 17574

Trending Articles


Download: Don Kingston ft General Kanene – Landlord(Prod by Great Pro)


Neem Baba Extra Questions Answer Class 6 English Poorvi


Deceased’s neighbours puzzled


CVP measurement


Practice Sheet of Right form of verbs for HSC Students


The Old Stag Class 4 Extra Questions MCQ English Chapter 5


Shaun Waring – Buxton


FREE BMW HUTOOLS 2.6 PRE


Verna Mae Skarsten


Mahakal Attitude Status



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>