2

what I want to do is create a task list which is dynamic. Meaning when I have five tasks (task1 - task5) and I get another more important one (task6) which is more important than say task2, I need to get task6 between task1 and task2 and thus postponing the start and end of task2 - task5 for the time it takes to finish task6.

Is there a way to do this with SharePoint?

Thanks in advance.

2

What I understand is you want to rearrange your tasks in the Task List priority wise. So I am giving answer on my assumption. According to my assumption you did not need to create Task list dynamically. Let me know if my assumption is correct or wrong without being rude !!

So for this you can create an Event Receiver which can fire when any new item has been added and in that event you can write the code to rearrange your tasks.

The sample code for rearranging list item is as given below:

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("http://localhost"))
         {
            using (SPWeb web = site.OpenWeb())
            {
               // Build a query.
               SPQuery query = new SPQuery();
               query.Query = string.Concat(
                              "<Where><Eq>",
                                 "<FieldRef Name='Status'/>",
                                 "<Value Type='CHOICE'>Not Started</Value>",
                              "</Eq></Where>",
                              "<OrderBy>",
                                 "<FieldRef Name='DueDate' Ascending='TRUE' />",
                                 "<FieldRef Name=’Priority’ Ascending='TRUE' />", 
                              "</OrderBy>");                    

               query.ViewFields = string.Concat(
                                   "<FieldRef Name='AssignedTo' />",
                                   "<FieldRef Name='LinkTitle' />",
                                   "<FieldRef Name='DueDate' />",
                                   "<FieldRef Name='Priority' />");

               query.ViewFieldsOnly = true; // Fetch only the data that we need.

               // Get data from a list.
               string listUrl = web.ServerRelativeUrl + "/lists/tasks";
               SPList list = web.GetList(listUrl);
               SPListItemCollection items = list.GetItems(query);

               // Print a report header.
               Console.WriteLine("{0,-25}  {1,-20}  {2,-25}  {3}",
                  "Assigned To", "Task", "Due Date", "Priority");

               // Print the details.
               foreach (SPListItem item in items)
               {
                  Console.WriteLine("{0,-25}  {1,-20}  {2,-25}  {3}",
                     item["AssignedTo"], item["LinkTitle"], item["DueDate"], item["Priority"]);
               }
            }
         }
         Console.ReadLine();
      }
   }
}

The above code I found here.

Let me know your thoughts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.