Wednesday 16 September 2015

Event Receivers BeforeProperties and AfterProperties

SharePoint 2010 Create Monthly Timer Job Which Execut On Last Day Of Month

      
 MonthlyTJService is helper class in which your logic for timer job is implemented



       string MonthlyTJ = "Monthly TJ";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
                 SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPSite site = properties.Feature.Parent as SPSite;
                    DeleteJob(site);
                    CreateJob(site);
                });
          
         }

        private static void DeleteJob(SPSite site)
        {
            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                 job.Delete();
            }
        }

        private static void CreateJob(SPSite site)
        {
            if (site == null)
                throw new ArgumentNullException("site", "site is null.");
          
            MonthlyTJService monthlyTJ = new MonthlyTJService(MonthlyTJ, site.WebApplication);
            SPMonthlySchedule monthlyTJSchedule = new SPMonthlySchedule()
            {
                BeginDay = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month),
                EndDay = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month),
                BeginHour = 23,
                BeginMinute = 15,
                EndHour = 23,
                EndMinute = 45
            };

            monthlyTJ.Schedule = monthlyTJSchedule;
            monthlyTJ.Properties.Add("siteurl", site.Url);
            monthlyTJ.Update();
       }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            DeleteJob(properties.Feature.Parent as SPSite); // Delete the Job
        }

SharePoint 2010 CAML Query For Search Within Folder

Search For Non Lookup Field Value

   <Query>
       <Where>
           <Eq>
               <FieldRef Name='Title'/>
               <Value Type='Text'>Val</Value>
           </Eq>
       </Where>
   <Query>
   <QueryOptions>
       <ViewAttributes Scope='Recursive' />
   </QueryOptions>



Search For Lookup Field Value 

   <Query>
       <Where>
           <Eq>
               <FieldRef Name='Title' LookupId='True'/>
               <Value Type='Lookup'>Val</Value>
           </Eq>
       </Where>
   <Query>
   <QueryOptions>
       <ViewAttributes Scope='Recursive' />
   </QueryOptions>