Example #1
0
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
            //ExStart: AddExtendedAttributesToRAWithLookUp
            // Create new project
            Project project = new Project(dataDir + "Blank2010.mpp");

            // Assign resource "1 TRG: Trade Group" to the "TASK 1" by creating a ResourceAssignment object.
            Resource resource = project.Resources.GetById(1);
            Task     task     = project.RootTask.Children.GetById(1);

            ResourceAssignment assignment = project.ResourceAssignments.Add(task, resource);

            // Create custom attribute definition with lookup.
            ExtendedAttributeDefinition resCostAttr = ExtendedAttributeDefinition.CreateLookupResourceDefinition(
                CustomFieldType.Cost,
                ExtendedAttributeResource.Cost5,
                "My lookup resource cost");

            project.ExtendedAttributes.Add(resCostAttr);

            var value1 = new Value {
                NumberValue = 1500, Description = "Val 1", Id = 1, Val = "1500"
            };

            resCostAttr.AddLookupValue(value1);

            resCostAttr.AddLookupValue(new Value {
                NumberValue = 2500, Description = "Val 2", Id = 2
            });

            // This value can be seen in "Resource usage" view of MS Project.
            var attributeValue = resCostAttr.CreateExtendedAttribute(value1);

            assignment.ExtendedAttributes.Add(attributeValue);

            // Create custom attribute definition with lookup.
            ExtendedAttributeDefinition taskCostAttr = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                ExtendedAttributeTask.Cost4,
                "My lookup task cost");

            project.ExtendedAttributes.Add(taskCostAttr);

            var taskLookupValue1 = new Value {
                NumberValue = 18, Description = "Task val 1", Id = 3, Val = "18"
            };

            taskCostAttr.AddLookupValue(taskLookupValue1);

            resCostAttr.AddLookupValue(new Value {
                NumberValue = 30, Description = "Task val 2", Id = 4
            });

            // This value can be seen in "Task usage" view of MS Project.
            assignment.ExtendedAttributes.Add(taskCostAttr.CreateExtendedAttribute(taskLookupValue1));

            project.Save(dataDir + "AddExtendedAttributesToRAWithLookUp_out.mpp", SaveFileFormat.MPP);
            //ExEnd: AddExtendedAttributesToRAWithLookUp
        }
Example #2
0
        public void CreateExtendedAttributeValueGuid()
        {
            // ExStart
            // ExFor: ExtendedAttribute.ValueGuid
            // ExSummary: Shows how to work with an extended attribute GUID.
            var project    = new Project();
            var definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Cost, ExtendedAttributeTask.Cost1, "My lookup cost");
            var finished   = project.RootTask.Children.Add("Task");

            finished.Set(Tsk.Start, new DateTime(2020, 4, 21, 8, 0, 0));
            finished.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));
            finished.Set(Tsk.Finish, new DateTime(2020, 4, 21, 17, 0, 0));

            var value1 = new Value {
                NumericValue = 10000, Description = "Val 1", Id = 1
            };
            var value2 = new Value {
                NumericValue = 25000, Description = "Val 2", Id = 2
            };

            definition.AddLookupValue(value1);
            definition.AddLookupValue(value2);

            var attribute = definition.CreateExtendedAttribute(value1);

            // extended attribute has a GUID which is
            // equal to GUID of bind 'Value' from the lookup
            Console.WriteLine("Extended attribute GUID: " + attribute.ValueGuid);
            Console.WriteLine("GUID of the first value in the lookup: " + value1.ValueGuid.ToString().ToUpper());
            var guidFromString = Guid.Parse(attribute.ValueGuid);

            Console.WriteLine("Are these GUIDs equal: " + guidFromString.Equals(value1.ValueGuid));

            // ExEnd
            Assert.IsTrue(guidFromString.Equals(value1.ValueGuid));
        }
        public static void Run()
        {
            // This example requires Aspose.Task for .NET, a trial version can be download from  http://www.aspose.com/corporate/purchase/temporary-license.aspx
            try
            {
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                //ExStart:WriteUpdatedExtendedAttributeDefinitions
                Project project = new Project(dataDir + "WriteUpdatedExtendedAttributeDefinitions.mpp");

                // Add new text3 extended attribute with lookup and one lookup value
                ExtendedAttributeDefinition taskTextAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Text3, "New text3 attribute");
                taskTextAttributeDefinition.ElementType = ElementType.Task;
                project.ExtendedAttributes.Add(taskTextAttributeDefinition);

                Value textVal = new Value();
                textVal.Id          = 1;
                textVal.Description = "Text value descr";
                textVal.Val         = "Text value1";

                taskTextAttributeDefinition.AddLookupValue(textVal);

                // Add new cost1 extended attribute with lookup and two cost values
                ExtendedAttributeDefinition taskCostAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Cost1, "New cost1 attribute");
                project.ExtendedAttributes.Add(taskCostAttributeDefinition);

                Value costVal1 = new Value();
                costVal1.Id          = 2;
                costVal1.Description = "Cost value 1 descr";
                costVal1.Val         = "99900";

                Value costVal2 = new Value();
                costVal2.Id          = 3;
                costVal2.Description = "Cost value 2 descr";
                costVal2.Val         = "11100";

                taskCostAttributeDefinition.AddLookupValue(costVal1);
                taskCostAttributeDefinition.AddLookupValue(costVal2);

                // Add new task and assign attribute lookup value.
                Task task = project.RootTask.Children.Add("New task");

                ExtendedAttribute taskAttr = taskCostAttributeDefinition.CreateExtendedAttribute(costVal1);
                task.ExtendedAttributes.Add(taskAttr);

                ExtendedAttributeDefinition taskStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Start7, "New start 7 attribute");

                Value startVal = new Value();
                startVal.Id            = 4;
                startVal.DateTimeValue = DateTime.Now;
                startVal.Description   = "Start 7 value description";

                taskStartAttributeDefinition.AddLookupValue(startVal);

                project.ExtendedAttributes.Add(taskStartAttributeDefinition);

                ExtendedAttributeDefinition taskFinishAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Finish4, "New finish 4 attribute");

                Value finishVal = new Value();
                finishVal.Id            = 5;
                finishVal.DateTimeValue = DateTime.Now;
                finishVal.Description   = "Finish 4 value description";

                taskFinishAttributeDefinition.ValueList.Add(finishVal);

                project.ExtendedAttributes.Add(taskFinishAttributeDefinition);

                ExtendedAttributeDefinition numberAttributeDefinition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(ExtendedAttributeTask.Number20, "New number attribute");

                Value val1 = new Value();
                val1.Id          = 6;
                val1.Val         = "1";
                val1.Description = "Number 1 value";
                Value val2 = new Value();
                val2.Id          = 7;
                val2.Val         = "2";
                val2.Description = "Number 2 value";
                Value val3 = new Value();
                val2.Id          = 8;
                val3.Val         = "3";
                val3.Description = "Number 3 value";

                numberAttributeDefinition.AddLookupValue(val1);
                numberAttributeDefinition.AddLookupValue(val2);
                numberAttributeDefinition.AddLookupValue(val3);

                project.ExtendedAttributes.Add(numberAttributeDefinition);

                ExtendedAttributeDefinition rscStartAttributeDefinition = ExtendedAttributeDefinition.CreateLookupResourceDefinition(ExtendedAttributeResource.Start5, "New start5 attribute");

                Value startVal2 = new Value();
                startVal2.Id            = 9;
                startVal2.DateTimeValue = DateTime.Now;
                startVal2.Description   = "this is start5 value descr";

                rscStartAttributeDefinition.AddLookupValue(startVal2);

                project.ExtendedAttributes.Add(rscStartAttributeDefinition);

                // Define a duration attribute without lookup.
                ExtendedAttributeDefinition taskDurationAttributeDefinition = ExtendedAttributeDefinition.CreateTaskDefinition(ExtendedAttributeTask.Duration1, "New Duration");
                project.ExtendedAttributes.Add(taskDurationAttributeDefinition);

                // Add new task and assign duration value to the previously defined duration attribute.
                Task timeTask = project.RootTask.Children.Add("New task");

                ExtendedAttribute durationExtendedAttribute = taskDurationAttributeDefinition.CreateExtendedAttribute();

                durationExtendedAttribute.DurationValue = project.GetDuration(3.0, TimeUnitType.Hour);
                timeTask.ExtendedAttributes.Add(durationExtendedAttribute);

                MPPSaveOptions mppSaveOptions = new MPPSaveOptions();
                mppSaveOptions.WriteViewData = true;

                // Save the project as MPP project file
                project.Save(dataDir + "WriteUpdatedExtendedAttributeDefinitions_out.mpp", mppSaveOptions);
                //ExEnd:WriteUpdatedExtendedAttributeDefinitions
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", "TestProject.mpp");

            Project myProject = new Project(filePath);


            ExtendedAttributeDefinition attribute = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Test Attribute");

            Value value1 = new Value
            {
                Id          = 1,
                StringValue = "Server/Database",
                Description = "DataBase of Server Side"
            };

            Value value2 = new Value
            {
                Id          = 2,
                StringValue = "Server/Api",
                Description = "Api of Server Side"
            };

            Value value3 = new Value
            {
                Id          = 3,
                StringValue = "Client/WebUI",
                Description = "WebUI of Client Side"
            };

            attribute.AddLookupValue(value1);

            attribute.AddLookupValue(value2);

            attribute.AddLookupValue(value3);

            myProject.ExtendedAttributes.Add(attribute);


            ExtendedAttribute serverDatabaseAttribute = attribute.CreateExtendedAttribute(value1);

            ExtendedAttribute serverApiAttribute = attribute.CreateExtendedAttribute(value2);

            ExtendedAttribute clientUIAttribute = attribute.CreateExtendedAttribute(value3);


            Task task1 = myProject.RootTask.Children.Add("Task 1");

            task1.ExtendedAttributes.Add(serverDatabaseAttribute);


            Task task2 = myProject.RootTask.Children.Add("Task 2");

            task2.ExtendedAttributes.Add(serverDatabaseAttribute);


            Task task3 = myProject.RootTask.Children.Add("Task 3");

            task3.ExtendedAttributes.Add(serverApiAttribute);


            Task task4 = myProject.RootTask.Children.Add("Task 4");

            task4.ExtendedAttributes.Add(clientUIAttribute);

            myProject.Save(filePath, SaveFileFormat.MPP);
        }
        public void WorkWithValue()
        {
            // ExStart
            // ExFor: Value
            // ExFor: Value.#ctor
            // ExFor: Value.Id
            // ExFor: Value.Val
            // ExFor: Value.ValueGuid
            // ExFor: Value.Description
            // ExFor: Value.StringValue
            // ExFor: Value.Phonetic
            // ExFor: Value.Duration
            // ExFor: Value.DateTimeValue
            // ExFor: Value.NumericValue
            // ExSummary: Shows how to read work with lookup values.
            var project = new Project(DataDir + "ReadTaskExtendedAttributes.mpp");

            // Create an Extended Attribute Definition of Text type
            var textLookup = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                CustomFieldType.Text,
                ExtendedAttributeTask.Text2,
                "Task Towns Name");

            // Add lookup values for the extended attribute definition
            textLookup.AddLookupValue(new Value {
                Id = 1, StringValue = "Town1", Description = "This is Town1", Phonetic = "Town One"
            });
            textLookup.AddLookupValue(new Value {
                Id = 2, StringValue = "Town2", Description = "This is Town2", Phonetic = "Town Two"
            });

            Console.WriteLine("Iterate over text lookup values:");
            foreach (var value in textLookup.ValueList)
            {
                Console.WriteLine("Id: " + value.Id);
                Console.WriteLine("GUID: " + value.ValueGuid);
                Console.WriteLine("Value: " + value.Val);
                Console.WriteLine("String Value: " + value.StringValue);
                Console.WriteLine("Description: " + value.Description);
                Console.WriteLine("Phonetic: " + value.Phonetic);
                Console.WriteLine();
            }

            // Create an Extended Attribute Definition of Duration type
            var durationLookup = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                CustomFieldType.Duration,
                ExtendedAttributeTask.Duration1,
                "Custom Durations");

            // Add lookup values for the extended attribute definition
            durationLookup.AddLookupValue(new Value {
                Id = 3, Duration = project.GetDuration(4, TimeUnitType.Hour), Description = "4 hours", Phonetic = "Four hours"
            });
            durationLookup.AddLookupValue(new Value {
                Id = 4, Duration = project.GetDuration(8, TimeUnitType.Hour), Description = "1 day", Phonetic = "One day"
            });
            durationLookup.AddLookupValue(new Value {
                Id = 5, Duration = project.GetDuration(1, TimeUnitType.Hour), Description = "1 hour", Phonetic = "One hour"
            });
            durationLookup.AddLookupValue(new Value {
                Id = 6, Duration = project.GetDuration(10, TimeUnitType.Day), Description = "10 days", Phonetic = "Ten days"
            });

            Console.WriteLine("Iterate over duration lookup values:");
            foreach (var value in durationLookup.ValueList)
            {
                Console.WriteLine("Id: " + value.Id);
                Console.WriteLine("GUID: " + value.ValueGuid);
                Console.WriteLine("Value: " + value.Val);
                Console.WriteLine("Duration: " + value.Duration);
                Console.WriteLine("Description: " + value.Description);
                Console.WriteLine("Phonetic: " + value.Phonetic);
                Console.WriteLine();
            }

            // Create an Extended Attribute Definition of Date type
            var dateLookup = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                CustomFieldType.Date,
                ExtendedAttributeTask.Date1,
                "Custom Date");

            dateLookup.AddLookupValue(new Value {
                Id = 7, DateTimeValue = new DateTime(2020, 4, 27, 8, 0, 0), Description = "Start Date", Phonetic = "Start Date"
            });

            Console.WriteLine("Iterate over date lookup values:");
            foreach (var value in dateLookup.ValueList)
            {
                Console.WriteLine("Id: " + value.Id);
                Console.WriteLine("GUID: " + value.ValueGuid);
                Console.WriteLine("Value: " + value.Val);
                Console.WriteLine("DateTime Value: " + value.DateTimeValue);
                Console.WriteLine("Description: " + value.Description);
                Console.WriteLine("Phonetic: " + value.Phonetic);
                Console.WriteLine();
            }

            // Create an Extended Attribute Definition of Number type
            var numericLookup = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                CustomFieldType.Number,
                ExtendedAttributeTask.Number1,
                "Number of tons");

            numericLookup.AddLookupValue(new Value {
                Id = 8, NumericValue = 10, Description = "10 tons", Phonetic = "Ten tons"
            });
            numericLookup.AddLookupValue(new Value {
                Id = 9, NumericValue = 20, Description = "20 tons", Phonetic = "Twenty tons"
            });
            numericLookup.AddLookupValue(new Value {
                Id = 10, NumericValue = 30, Description = "30 tons", Phonetic = "Thirty tons"
            });

            Console.WriteLine("Iterate over numeric lookup values:");
            foreach (var value in numericLookup.ValueList)
            {
                Console.WriteLine("Id: " + value.Id);
                Console.WriteLine("GUID: " + value.ValueGuid);
                Console.WriteLine("Value: " + value.Val);
                Console.WriteLine("Numeric Value: " + value.NumericValue);
                Console.WriteLine("Description: " + value.Description);
                Console.WriteLine("Phonetic: " + value.Phonetic);
                Console.WriteLine();
            }

            project.ExtendedAttributes.Add(textLookup);
            project.ExtendedAttributes.Add(durationLookup);
            project.ExtendedAttributes.Add(dateLookup);
            project.ExtendedAttributes.Add(numericLookup);
            // ExEnd
        }
        public static void Run()
        {
            try
            {
                //ExStart:AddTaskExtendedAttributes
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

                // Create new project
                Project project = new Project(dataDir + "Blank2010.mpp");

                //Create an Extended Attribute Definition of Text1 type
                var taskExtendedAttributeText1Definition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Task City Name");

                //Add it to the project's Extended Attributes collection
                project.ExtendedAttributes.Add(taskExtendedAttributeText1Definition);

                //Add a task to the project
                var task = project.RootTask.Children.Add("Task 1");

                //Create an Extended Attribute from the Attribute Definition
                var taskExtendedAttributeText1 = taskExtendedAttributeText1Definition.CreateExtendedAttribute();

                //Assign a value to the generated Extended Attribute. The type of the attribute is "Text", the "TextValue" property should be used.
                taskExtendedAttributeText1.TextValue = "London";

                //Add the Extended Attribute to task
                task.ExtendedAttributes.Add(taskExtendedAttributeText1);

                project.Save(dataDir + "PlainTextExtendedAttribute_out.mpp", SaveFileFormat.MPP);

                Project project1 = new Project(dataDir + "Blank2010.mpp");

                //Create an Extended Attribute Definition of Text2 type
                var taskExtendedAttributeText2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text2, "Task Towns Name");

                //Add lookup values for the extended attribute definition
                taskExtendedAttributeText2Definition.AddLookupValue(new Value {
                    Id = 1, StringValue = "Town1", Description = "This is Town1"
                });
                taskExtendedAttributeText2Definition.AddLookupValue(new Value {
                    Id = 2, StringValue = "Town2", Description = "This is Town2"
                });

                //Add it to the porject's Extended Attributes collection
                project1.ExtendedAttributes.Add(taskExtendedAttributeText2Definition);

                //Add a task to the project
                var task2 = project1.RootTask.Children.Add("Task 2");

                //Crate an Extended Attribute from the Text2 Lookup Definition for Id 1
                var taskExtendedAttributeText2 = taskExtendedAttributeText2Definition.CreateExtendedAttribute(taskExtendedAttributeText2Definition.ValueList[1]);

                //Add the Extended Attribute to task
                task2.ExtendedAttributes.Add(taskExtendedAttributeText2);

                project1.Save(dataDir + "TextExtendedAttributeWithLookup_out.mpp", SaveFileFormat.MPP);

                Project project2 = new Project(dataDir + "Blank2010.mpp");

                //Create an Extended Attribute Definition of Duration2 type
                var taskExtendedAttributeDuration2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Duration, ExtendedAttributeTask.Duration2, "Some duration");

                //Add lookup values for extended attribute definition
                taskExtendedAttributeDuration2Definition.AddLookupValue(new Value {
                    Id = 2, Duration = project2.GetDuration(4, TimeUnitType.Hour), Description = "4 hours"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(new Value {
                    Id = 3, Duration = project2.GetDuration(1, TimeUnitType.Day), Description = "1 day"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(new Value {
                    Id = 4, Duration = project2.GetDuration(1, TimeUnitType.Hour), Description = "1 hour"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(new Value {
                    Id = 7, Duration = project2.GetDuration(10, TimeUnitType.Day), Description = "10 days"
                });

                //Add the definition to the project's Extended Attributes collection
                project2.ExtendedAttributes.Add(taskExtendedAttributeDuration2Definition);

                //Add a task to the project
                var task3 = project2.RootTask.Children.Add("Task 3");

                //Create an Extended Attribute from the Duration2 Lookup Definition for Id 3
                var taskExtendedAttributeDuration2 = taskExtendedAttributeDuration2Definition.CreateExtendedAttribute(taskExtendedAttributeDuration2Definition.ValueList[3]);

                //Add the Extended Attribute to task
                task3.ExtendedAttributes.Add(taskExtendedAttributeDuration2);

                project2.Save(dataDir + "DurationExtendedAttributeWithLookup_out.mpp", SaveFileFormat.MPP);

                Project project3 = new Project(dataDir + "Blank2010.mpp");

                //Create an Extended Attribute Definition of Finish2 Type
                var taskExtendedAttributeFinish2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Finish, ExtendedAttributeTask.Finish2, "Some finish");

                //Add lookup values for extended attribute defintion
                taskExtendedAttributeFinish2Definition.AddLookupValue(new Value {
                    Id = 2, DateTimeValue = new DateTime(1984, 01, 01, 00, 00, 01), Description = "This is Value2"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(new Value {
                    Id = 3, DateTimeValue = new DateTime(1994, 01, 01, 00, 01, 01), Description = "This is Value3"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(new Value {
                    Id = 4, DateTimeValue = new DateTime(2009, 12, 31, 00, 00, 00), Description = "This is Value4"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(new Value {
                    Id = 7, DateTimeValue = DateTime.Now, Description = "This is Value6"
                });

                //Add the definition to the project's Extended Attributes collection
                project3.ExtendedAttributes.Add(taskExtendedAttributeFinish2Definition);

                //Add a task to the project
                var task4 = project3.RootTask.Children.Add("Task 4");

                //Create an Extneded Attribute from the Finish2 Lookup Definition for Id 3
                var taskExtendedAttributeFinish2 = taskExtendedAttributeFinish2Definition.CreateExtendedAttribute(taskExtendedAttributeFinish2Definition.ValueList[3]);

                //Add the Extended Attribute to task
                task4.ExtendedAttributes.Add(taskExtendedAttributeFinish2);

                // Save the Project
                project3.Save(dataDir + "FinishExtendedAttributeWithLookup_out.mpp", SaveFileFormat.MPP);

                //ExEnd:AddTaskExtendedAttributes
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }
Example #7
0
        public void ReadWriteTaskExtendedAttributes()
        {
            try
            {
                // ExStart:ReadWriteTaskExtendedAttributes
                // ExFor: Task.ExtendedAttributes
                // ExSummary: Shows how to read task extended attributes.
                var project = new Project(DataDir + "ReadTaskExtendedAttributes.mpp");

                // Create extended attribute definition
                var definition = ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Start, ExtendedAttributeTask.Start7, "Start 7");
                project.ExtendedAttributes.Add(definition);

                // Get zero index task
                var tsk = project.RootTask.Children.GetById(1);

                // Add extended attribute
                var extendedAttribute = definition.CreateExtendedAttribute();
                extendedAttribute.DateValue = DateTime.Now;

                // Also the following short syntax can be used: ExtendedAttribute attribute = attributeDefinition.CreateExtendedAttribute(DateTime.Now);
                tsk.ExtendedAttributes.Add(extendedAttribute);

                // Create an Extended Attribute Definition of Text1 type
                var taskExtendedAttributeText1Definition =
                    ExtendedAttributeDefinition.CreateTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text1, "Task City Name");

                // Add it to the project's Extended Attributes collection
                project.ExtendedAttributes.Add(taskExtendedAttributeText1Definition);

                var newTask = project.RootTask.Children.Add("Task 1");

                // Create an Extended Attribute from the Attribute Definition
                var taskExtendedAttributeText1 = taskExtendedAttributeText1Definition.CreateExtendedAttribute();

                // Assign a value to the generated Extended Attribute. The type of the attribute is "Text", the "TextValue" property should be used.
                taskExtendedAttributeText1.TextValue = "London";

                // Add the Extended Attribute to task
                newTask.ExtendedAttributes.Add(taskExtendedAttributeText1);

                // Create an Extended Attribute Definition of Text2 type
                var taskExtendedAttributeText2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                    CustomFieldType.Text,
                    ExtendedAttributeTask.Text2,
                    "Task Towns Name");

                // Add lookup values for the extended attribute definition
                taskExtendedAttributeText2Definition.AddLookupValue(new Value {
                    Id = 1, StringValue = "Town1", Description = "This is Town1"
                });
                taskExtendedAttributeText2Definition.AddLookupValue(new Value {
                    Id = 2, StringValue = "Town2", Description = "This is Town2"
                });

                // Add it to the project's Extended Attributes collection
                project.ExtendedAttributes.Add(taskExtendedAttributeText2Definition);

                var task2 = project.RootTask.Children.Add("Task 2");

                // Crate an Extended Attribute from the Text2 Lookup Definition for Id 1
                var taskExtendedAttributeText2 = taskExtendedAttributeText2Definition.CreateExtendedAttribute(taskExtendedAttributeText2Definition.ValueList[1]);

                // Add the Extended Attribute to task
                task2.ExtendedAttributes.Add(taskExtendedAttributeText2);

                // Create an Extended Attribute Definition of Duration2 type
                var taskExtendedAttributeDuration2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                    CustomFieldType.Duration,
                    ExtendedAttributeTask.Duration2,
                    "Some duration");

                // Add lookup values for extended attribute definition
                taskExtendedAttributeDuration2Definition.AddLookupValue(
                    new Value {
                    Id = 3, Duration = project.GetDuration(4, TimeUnitType.Hour), Description = "4 hours"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(new Value {
                    Id = 4, Duration = project.GetDuration(1, TimeUnitType.Day), Description = "1 day"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(
                    new Value {
                    Id = 5, Duration = project.GetDuration(1, TimeUnitType.Hour), Description = "1 hour"
                });
                taskExtendedAttributeDuration2Definition.AddLookupValue(
                    new Value {
                    Id = 6, Duration = project.GetDuration(10, TimeUnitType.Day), Description = "10 days"
                });

                // Add the definition to the project's Extended Attributes collection
                project.ExtendedAttributes.Add(taskExtendedAttributeDuration2Definition);

                var task3 = project.RootTask.Children.Add("Task 3");

                // Create an Extended Attribute from the Duration2 Lookup Definition for Id 3
                var taskExtendedAttributeDuration2 =
                    taskExtendedAttributeDuration2Definition.CreateExtendedAttribute(taskExtendedAttributeDuration2Definition.ValueList[3]);

                // Add the Extended Attribute to task
                task3.ExtendedAttributes.Add(taskExtendedAttributeDuration2);

                // Create an Extended Attribute Definition of Finish2 Type
                var taskExtendedAttributeFinish2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(
                    CustomFieldType.Finish,
                    ExtendedAttributeTask.Finish2,
                    "Some finish");

                // Add lookup values for extended attribute definition
                taskExtendedAttributeFinish2Definition.AddLookupValue(
                    new Value {
                    Id = 7, DateTimeValue = new DateTime(1984, 01, 01, 00, 00, 01), Description = "This is Value2"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(
                    new Value {
                    Id = 8, DateTimeValue = new DateTime(1994, 01, 01, 00, 01, 01), Description = "This is Value3"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(
                    new Value {
                    Id = 9, DateTimeValue = new DateTime(2009, 12, 31, 00, 00, 00), Description = "This is Value4"
                });
                taskExtendedAttributeFinish2Definition.AddLookupValue(new Value {
                    Id = 10, DateTimeValue = DateTime.Now, Description = "This is Value6"
                });

                // Add the definition to the project's Extended Attributes collection
                project.ExtendedAttributes.Add(taskExtendedAttributeFinish2Definition);

                var task4 = project.RootTask.Children.Add("Task 4");

                // Create an Extended Attribute from the Finish2 Lookup Definition for Id 3
                var taskExtendedAttributeFinish2 = taskExtendedAttributeFinish2Definition.CreateExtendedAttribute(taskExtendedAttributeFinish2Definition.ValueList[3]);

                // Add the Extended Attribute to task
                task4.ExtendedAttributes.Add(taskExtendedAttributeFinish2);

                var collector = new ChildTasksCollector();
                TaskUtils.Apply(project.RootTask, collector, 0);

                // Read extended attributes for tasks
                foreach (var task in collector.Tasks)
                {
                    foreach (var attribute in task.ExtendedAttributes)
                    {
                        Console.WriteLine(attribute.FieldId);
                        Console.WriteLine(attribute.ValueGuid);

                        switch (attribute.AttributeDefinition.CfType)
                        {
                        case CustomFieldType.Date:
                        case CustomFieldType.Start:
                        case CustomFieldType.Finish:
                            Console.WriteLine(attribute.DateValue);
                            break;

                        case CustomFieldType.Text:
                            Console.WriteLine(attribute.TextValue);
                            break;

                        case CustomFieldType.Duration:
                            Console.WriteLine(attribute.DurationValue.ToString());
                            break;

                        case CustomFieldType.Cost:
                        case CustomFieldType.Number:
                            Console.WriteLine(attribute.NumericValue);
                            break;

                        case CustomFieldType.Flag:
                            Console.WriteLine(attribute.FlagValue);
                            break;

                        case CustomFieldType.Null:
                        case CustomFieldType.RBS:
                        case CustomFieldType.OutlineCode:
                            return;

                        default:
                            return;
                        }
                    }
                }

                project.Save(OutDir + "ReadWriteTaskExtendedAttributes_out.mpp", SaveFileFormat.MPP);

                // ExEnd:ReadWriteTaskExtendedAttributes
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(
                    ex.Message
                    + "\nThis example will only work if you apply a valid Aspose License. You can purchase full license or get 30 day temporary license from http://www.aspose.com/purchase/default.aspx.");
            }
        }