We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Data loss after saving project to mpp file (open with project 2016)

Hi,
Thanks for your works.

I’m using ms project 2016, and the latest version of Aspose.Tasks(17.8.0).
And some properties are missing when open the mpp file generated by Aspose.Tasks with Project 2016, here’s the sample:
Reproduce.zip (164.1 KB)

Could anyone help me?
Thanks

@anobaka,

Thank you for contacting Aspose support team.

There seems some issue with your template file as it is working fine with the attached sample template file. Also please consider the following recommendations:

  • Try to set Start and Duration properties as Finish date will be calculated by the API.

  • Use Recalculate() function at end while using CalculationMode.Manual

Please give a try to the following sample code using attached template file and share the feedback.

var p = new Project("./Blank2010.mpp") { CalculationMode = CalculationMode.Manual };
var t = p.RootTask.Children.Add("Test");
t.Set(Tsk.Start, DateTime.Now);
t.Set(Tsk.Duration, p.GetDuration(5, TimeUnitType.Day));
//t.Set(Tsk.Finish, DateTime.Now.AddDays(5));
p.ResourceAssignments.Add(t, p.Resources.Add("Resource"));
p.Recalculate();
p.Save("./dest.mpp", new MPPSaveOptions { WriteViewData = true });

Blank2010.zip (22.6 KB)

@kashif.iqbal

Thank you for help. It works fine with the Blank2010.mpp template file. I guess there’s something wrong with my Project software(if I open Blank2010.mpp and just save it, then it doesn’t work.)

I’ve tried to change some default bar styles and save the project as mpp file and image, the code is here:

var p = new Project("./Blank2010.mpp") {CalculationMode = CalculationMode.Manual};
var now = DateTime.Now;
//Main task
var main = p.RootTask.Children.Add("Main");
main.Set(Tsk.Start, now);
main.Set(Tsk.Duration, p.GetDuration(5, TimeUnitType.Day));
//Sub task
var sub = main.Children.Add("Sub");
sub.Set(Tsk.Start, now);
sub.Set(Tsk.Duration, p.GetDuration(5, TimeUnitType.Day));
p.ResourceAssignments.Add(sub, p.Resources.Add("Resource"));
p.Recalculate();
//Change bar styles
if (p.DefaultView is GanttChartView view)
{
    var bs = view.BarStyles.FirstOrDefault(a => a.Name == "Manual Summary Rollup");
    bs.LeftField = Field.TaskStart;
    bs.TopField = Field.TaskName;
}
p.Save("./dest.mpp", new MPPSaveOptions {WriteViewData = true});
p.Save("./dest.png",
    new ImageSaveOptions(SaveFileFormat.PNG)
    {
        BarStyles = new List<BarStyle> {new BarStyle {ItemType = BarItemType.ManualTask}},
        DrawNonWorkingTime = true,
        FitContent = true,
        PresentationFormat = PresentationFormat.GanttChart,
        ShowProjectSummaryTask = true
    });

But there are still some questions in my mind, could you help me please?

  1. When I open the mpp file, the task name and task start don’t show in the gantt chart view as expected unless I clear the fields and reset them manually, how can I fix it?
    image.png (45.5 KB)

  2. In bar styles, all values of From and To fields became Scheduled XXX from Task XXX (e.g. Task Start -> Scheduled Start). Does it matter? If it does, how can I restore them?

  3. How can I expand all tasks and their sub tasks when I save the project as an image?

Thanks a lot.

@anobaka,

We are working on this query and will soon share our findings with you here. We appreciate your patience until then.

@kashif.iqbal

Really appreciate it.

I tried to replace this line

p.Save("./dest.png", 

to

new Project("./dest.mpp").Save("./dest.png",

and the sub tasks showed up… Must I save the mpp file before saving project to an image?

And

  1. It seems that SaveOptions.BarStyles is not powerful as GanttChartView.BarStyles (e.g. SaveOptions.BarStyles can not specific the positions of texts). how can I apply all of the GanttChartView.BarStyles to an image? (just like Select Tasks -> Copy Picture function in Project 2016).

Thanks

@anobaka,

Following are the responses to your queries:

You may please use following sample code to display text in gantt chart view.

static void Test()
{
    try
    {
        // The path to the documents directory.
        string dataDir = "./";
        Project project = new Project("Blank2010.mpp") {  CalculationMode = CalculationMode.Manual};

        Task child1 = project.RootTask.Children.Add("Child 1");
        child1.Set(Tsk.Start, new DateTime(2017, 9, 6, 8, 0, 0));
        child1.Set(Tsk.Duration, project.GetDuration(1, TimeUnitType.Day));


        GanttChartView view = project.DefaultView as GanttChartView;
        GanttBarStyle custom = GetCustomBarStyle();

        // Add the custom bar style to the custom bar collection of the project view
        view.CustomBarStyles.Add(custom);

        string file = "ImplementCustomBarStyleWriting_out.mpp";

        MPPSaveOptions options = new MPPSaveOptions();
        options.WriteViewData = true;
        project.Recalculate();

        project.Save(dataDir + file, options);
        //project.Save(dataDir + "output1.png", SaveFileFormat.PNG);
        //new Project(dataDir + file).Save(dataDir + "output2.png", SaveFileFormat.PNG);
    }
    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.");
    }
}

private static GanttBarStyle GetCustomBarStyle()
{
    GanttBarStyle style = new GanttBarStyle();
    style.ShowFor = "1";
    style.MiddleShape = GanttBarMiddleShape.RectangleBottom;
    style.MiddleFillPattern = GanttBarFillPattern.MediumFill;
    style.MiddleShapeColor = Color.Blue;

    style.StartShape = GanttBarEndShape.ArrowDown;
    style.StartShapeColor = Color.Red;

    style.EndShape = GanttBarEndShape.ArrowUp;
    style.EndShapeColor = Color.Yellow;

    style.LeftField = Field.TaskResourceNames;
    style.RightField = Field.TaskName;
    style.TopField = Field.TaskStart;
    style.BottomField = Field.TaskFinish;
    style.InsideField = Field.TaskDuration;

    return style;
}

This issue is observed and logged under Id: TASKSNET-2092 for further investigation by the product team.

This also seems to be an issue as without saving the file to disc, child tasks are not rendered to the image. This issue is also logged under Id: TASKSNET-2093 for consideration of the product team.

You are right that limited features are available to render gantt chart to image. I am afraid that all the features of GanttChartView.BarStyles are not available in SaveOptions.BarStyles.

You will be automatically notified once any update is received against the logged issues above. Also please create a new thread if you find any other issue or have any query related to Aspose.Tasks.

@kashif.iqbal

When I open the mpp file, the task name and task start don’t show in the gantt chart view as expected unless I clear the fields and reset them manually, how can I fix it?

This happens when I have sub tasks, the behaviors of styles of sub tasks are normal, but the styles of summary task are not shown on gantt chart view, but the styles are saved.

My apologies for previous queries are not related to this thread. I’ve opened a new thread.

Thanks for your guidance very much.

@anobaka,

Thank you for the feedback. This query is replied here.

@anobaka,

This issue has been fixed in latest version of Aspose.Tasks for .NET 17.9. Please let us know if we can be of any additional help to you with respect to your queries related to API.