Unable to replace calendar in a project

Hi,


I am unable to replace a calendar using this code Creating, Updating and Removing Calendar

Please provide solution.

Hi Robert,

Thank you for contacting Aspose support team.

Microsoft project does not allow deleting “Standard” calendar. Similarly Aspose.Tasks does not allow removing Standard calendar. You may please use following sample code to replace an existing calendar from the project and share the feedback.

Project project = new Project(@"Project1.mpp");
// Access project calendars
CalendarCollection calColl = project.Calendars;
foreach (ATasks.Calendar myCalendar in calColl)
{
    if (myCalendar.Name == "TestCalendar")
    {
        // Remove calendar
        calColl.Remove(myCalendar);
        break;
    }
}
// Add new calendar
ATasks.Calendar calendar = project.Calendars.Add("TestCalendar");
project.Save(@"Project1.mpp", SaveFileFormat.MPP);