Dear all,
I am running timer job to bring in some data sent to trainers. but the timer job is failing in central administration - without much information. When I try to debug the code said in one area trainer FullName - the CopyFieldMask value as 'trainer.CopyField.Mask' threw an exception of type 'System.ArgumentException'.
Can somebody throw light on this.
CS file for sending mail
using System; using System.Collections.Generic; using System.Linq; using System.Net.Mail; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace TTJ { public class TJInstructorSchedule :SPJobDefinition { public TJInstructorSchedule() : base() { } public TJInstructorSchedule(string jobName, SPService service, SPServer server, SPJobLockType targetType) : base(jobName, service, server, targetType) { } public TJInstructorSchedule(string jobName, SPWebApplication webApplication) : base(jobName, webApplication, null, SPJobLockType.ContentDatabase) { } public override void Execute(Guid targetInstanceId) { //Access the Trainers list SPWebApplication webApp = this.Parent as SPWebApplication; SPSite trainingSite = webApp.Sites["sites/training"]; SPWeb rootWeb = trainingSite.RootWeb; SPList trainersList = rootWeb.Lists["SessionTrainer"]; SPListItemCollection trainers = trainersList.Items; foreach (SPListItem trainer in trainers) { //Store the trainer's email address string trainerEmail = trainer["E-mail Address"].ToString(); //Store the trainer's Full name for future use string trainerFullName = trainer["Full Name"].ToString(); //Access the sessions list and retrieve session for this trainer that occur in the future SPList sessionList = rootWeb.Lists["SessionList"]; SPQuery getSessionsForTrainer = new SPQuery(); getSessionsForTrainer.ViewFields = "<FieldRef Name='CourseTitle'/><FieldRef Name='Trainer'/><FieldRef Name='TrainingVenue'/><FieldRef Name='RegisterInfo'/><FieldRef Name='StartDate'/><FieldRef Name='EndDate'/>"; //CAML getSessionsForTrainer.Query = "<Where><And><Eq><FieldRef Name='Trainer'/><Value Type='Lookup'>" + trainerFullName + "</Value></Eq><Geq><FieldRef Name='StartDate'/><Value Type='DateTime'><Today/></Value></Geq></And></Where>"; SPListItemCollection sessionsForTrainer = sessionList.GetItems(getSessionsForTrainer); //Iterate through the sessions and build an email to send to the Trainer string emailSubject = "Instructor Schedule for " + trainerFullName; string emailBody = ""; emailBody += "Hello " + trainerFullName +",<br/><br/>"; emailBody += "Here is your upcoming schedule. If you have any questions, please contact Judy Moore(Jmoore@ifmr.co.in) or Amanda Stevenson(astevenson@ifmr.co.in).<br/><br/>"; foreach (SPListItem scheduledSession in sessionsForTrainer) { emailBody += scheduledSession["CourseTitle"].ToString().Remove(0, 3) + " at " + scheduledSession["TrainingVenue"].ToString() + " starting at " + scheduledSession["StartDate"].ToString() + " and ending at " + scheduledSession["EndDate"].ToString() + ", which has " + scheduledSession["RegisterInfo"].ToString() + " registrations.<br/>"; } emailBody+="<br/>Thank you!<br/></br>"; emailBody += "Do not reply to this message; it is an automatically generated system message."; //send the mail MailMessage instructorScheduleEmail = new MailMessage("x@x.co.in", trainerEmail, emailSubject, emailBody); instructorScheduleEmail.IsBodyHtml = true; SmtpClient smtpClient = new SmtpClient("x"); smtpClient.Send(instructorScheduleEmail); } //base.Execute(targetInstanceId); } } }
eventreceiver file code
using System; using System.Runtime.InteropServices; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; using Microsoft.SharePoint.Security; namespace TTJ.Features.Feature_TTJ { /// <summary> /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade. /// </summary> /// <remarks> /// The GUID attached to this class may be used during packaging and should not be modified. /// </remarks> [Guid("a3ddf329-29a8-4748-b004-1efe1cc096f2")] public class Feature_TTJEventReceiver : SPFeatureReceiver { // Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebApplication webApp = properties.Feature.Parent as SPWebApplication; if (webApp.Name == "x - 47") { foreach (SPJobDefinition job in webApp.JobDefinitions) { if (job.Name == "Training Registration Portal - Instructor Schedules") { job.Delete(); } } TJInstructorSchedule tjSendSchedules = new TJInstructorSchedule("Training Registration Portal - Instructor Schedules", webApp); tjSendSchedules.Title = "Training Registration Portal - Instructor Schedules"; SPWeeklySchedule weeklySchedule = new SPWeeklySchedule(); weeklySchedule.BeginDayOfWeek = DayOfWeek.Friday; weeklySchedule.BeginHour = 16; weeklySchedule.EndDayOfWeek = DayOfWeek.Friday; weeklySchedule.EndHour = 17; tjSendSchedules.Schedule = weeklySchedule; tjSendSchedules.Update(); } } // Uncomment the method below to handle the event raised before a feature is deactivated. public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPWebApplication webApp = properties.Feature.Parent as SPWebApplication; if (webApp.Name == "x - 47") { foreach (SPJobDefinition job in webApp.JobDefinitions) { if (job.Name == "Training Registration Portal - Instructor Schedules") { job.Delete(); } } } } // Uncomment the method below to handle the event raised after a feature has been installed. //public override void FeatureInstalled(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised before a feature is uninstalled. //public override void FeatureUninstalling(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised when a feature is upgrading. //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters) //{ //} } }
Cheers
Sathya