static IEnumerable <Microsoft.Exchange.WebServices.Data.Task> FindIncompleteTask(ExchangeService service) { // Specify the folder to search, and limit the properties returned in the result. TasksFolder tasksfolder = TasksFolder.Bind(service, WellKnownFolderName.Tasks, new PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount)); // Set the number of items to the smaller of the number of items in the Contacts folder or 1000. int numItems = tasksfolder.TotalCount < 1000 ? tasksfolder.TotalCount : 1000; // Instantiate the item view with the number of items to retrieve from the contacts folder. ItemView view = new ItemView(numItems); // To keep the request smaller, send only the display name. view.PropertySet = new PropertySet(BasePropertySet.IdOnly, TaskSchema.Subject, TaskSchema.Status, TaskSchema.StartDate); var filter = new SearchFilter.IsGreaterThan(TaskSchema.DateTimeCreated, DateTime.Now.AddYears(-10)); // Retrieve the items in the Tasks folder with the properties you selected. FindItemsResults <Microsoft.Exchange.WebServices.Data.Item> taskItems = service.FindItems(WellKnownFolderName.Tasks, filter, view); // If the subject of the task matches only one item, return that task item. var results = new List <Microsoft.Exchange.WebServices.Data.Task>(); foreach (var task in taskItems) { var result = new Microsoft.Exchange.WebServices.Data.Task(service); result = task as Microsoft.Exchange.WebServices.Data.Task; results.Add(result); } return(results); }
public static Task FindTaskBySubject(ExchangeService service, string Subject) { // Specify the folder to search, and limit the properties returned in the result. TasksFolder tasksfolder = TasksFolder.Bind(service, WellKnownFolderName.Tasks, new PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount)); // Set the number of items to the smaller of the number of items in the Contacts folder or 1000. int numItems = tasksfolder.TotalCount < 1000 ? tasksfolder.TotalCount : 1000; // Instantiate the item view with the number of items to retrieve from the contacts folder. ItemView view = new ItemView(numItems); // To keep the request smaller, send only the display name. view.PropertySet = new PropertySet(BasePropertySet.IdOnly, TaskSchema.Subject); // Create a searchfilter to check the subject of the tasks. SearchFilter.IsEqualTo filter = new SearchFilter.IsEqualTo(TaskSchema.Subject, Subject); // Retrieve the items in the Tasks folder with the properties you selected. FindItemsResults <Item> taskItems = service.FindItems(WellKnownFolderName.Tasks, filter, view); // If the subject of the task matches only one item, return that task item. if (taskItems.Count() == 1) { return((Task)taskItems.Items[0]); } // No tasks, or more than one, were found. else { return(null); } }
/// <summary> /// The method will return all the tasks from "Tasks" folder /// </summary> /// <returns>List of tasks</returns> /// public FindItemsResults <Item> GetAllTasks() { // Specify the folder to search, and limit the properties returned in the result. TasksFolder tasksfolder = TasksFolder.Bind(Service, WellKnownFolderName.Tasks, new PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount)); // Set the count of items to be displayed. int numItems = tasksfolder.TotalCount > 50 ? tasksfolder.TotalCount : 50; // Instantiate the item view with the number of items to retrieve from the required folder. ItemView view = new ItemView(numItems); // Retrieve the items in the Tasks folder. FindItemsResults <Item> taskItems = Service.FindItems(WellKnownFolderName.Tasks, view); //Load Body and other Service.LoadPropertiesForItems(taskItems, PropertySet.FirstClassProperties); if (taskItems != null && taskItems.Count() > 0) { return(taskItems); } else { return(null); } }
private void bindTasks(DateTime fromDate, DateTime toDate) { List <LeadTask> tasks = null; Expression <Func <CRM.Data.Entities.Task, bool> > predicate = PredicateBuilder.True <CRM.Data.Entities.Task>(); if (roleID == (int)UserRole.Administrator) { } else if ((roleID == (int)UserRole.Client || roleID == (int)UserRole.SiteAdministrator) && clientID > 0) { // load all tasks for client (sort of admin) predicate = predicate.And(LeadTask => LeadTask.creator_id == clientID); predicate = predicate.And(LeadTask => LeadTask.start_date >= fromDate && LeadTask.end_date <= toDate); // get overdue task for client predicate = predicate.Or(LeadTask => LeadTask.status_id == 1 && LeadTask.end_date <= toDate && LeadTask.creator_id == clientID); } else { // regular users predicate = predicate.And(LeadTask => LeadTask.start_date >= fromDate && LeadTask.end_date <= toDate); predicate = predicate.And(LeadTask => LeadTask.owner_id == userID); } tasks = TasksManager.GetLeadTask(predicate, fromDate, toDate); if (rbOn.Checked) { userID = SessionHelper.getUserId(); CRM.Data.Entities.SecUser secUser = SecUserManager.GetByUserId(userID); string emailaddress = secUser.Email; string password = SecurityManager.Decrypt(secUser.emailPassword); string url = "https://" + secUser.emailHost + "/EWS/Exchange.asmx"; ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); service.Credentials = new WebCredentials(emailaddress, password); service.Url = new Uri(url); try { TasksFolder tasksfolder = TasksFolder.Bind(service, WellKnownFolderName.Tasks); ItemView view = new ItemView(int.MaxValue); FindItemsResults <Item> OutlookTasks = tasksfolder.FindItems(view); CalendarView calView = new CalendarView(fromDate, toDate); FindItemsResults <Item> instanceResults = service.FindItems(WellKnownFolderName.Calendar, calView); foreach (var item in instanceResults) { LeadTask newTask = new LeadTask(); Microsoft.Exchange.WebServices.Data.Appointment appointment = item as Microsoft.Exchange.WebServices.Data.Appointment; newTask.creator_id = userID; newTask.details = appointment.Subject; newTask.end_date = appointment.End; newTask.isAllDay = appointment.IsRecurring; newTask.text = appointment.Subject; newTask.priorityName = appointment.Importance.ToString(); newTask.owner_name = appointment.Organizer.Name; newTask.start_date = appointment.Start; tasks.Add(newTask); } foreach (var task in OutlookTasks) { task.Load(); Microsoft.Exchange.WebServices.Data.Task myTask = task as Microsoft.Exchange.WebServices.Data.Task; LeadTask newTask = new LeadTask(); newTask.creator_id = userID; newTask.details = ExtractHtmlInnerText(myTask.Body.Text); newTask.end_date = myTask.DueDate; newTask.isAllDay = myTask.IsRecurring; newTask.text = myTask.Subject; newTask.statusName = myTask.Status.ToString(); newTask.priorityName = myTask.Importance.ToString(); newTask.owner_name = myTask.Owner; if (myTask.StartDate == null) { newTask.start_date = myTask.DueDate; } else { newTask.start_date = myTask.StartDate; } tasks.Add(newTask); } } catch (Exception ex) { } } // show tasks gvTasks.DataSource = tasks; gvTasks.DataBind(); }