Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6185401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:42:14+00:00 2026-05-24T01:42:14+00:00

I’m trying to use MPXJ to create project file from a hierarchy that exists

  • 0

I’m trying to use MPXJ to create project file from a hierarchy that exists in my code. The following hierarchy needs to be converted:

  • Division
    • Customer
      • Contract
        • Projects
          • Project details (start/end dates, etc.)

My code for creating the .mpx is as follows:

private void BuildExport()
    {

        net.sf.mpxj.ProjectFile file = new net.sf.mpxj.ProjectFile();
        net.sf.mpxj.ProjectCalendar cal = file.addDefaultBaseCalendar();

        //Microsoft.Office.Interop.MSProject.Application projApp = new Microsoft.Office.Interop.MSProject.Application();
        //projApp.Visible = true;
        //projApp.FileNew();

        string firstDate = string.Empty;

        foreach (IZCpTreeViewItem div in Divisions)
        {
            net.sf.mpxj.Task divTask = file.addTask();
            divTask.setName(div.Name);

            //Microsoft.Office.Interop.MSProject.Task newTask = projApp.ActiveProject.Tasks.Add(div.Name);

            //newTask.OutlineLevel = 1;

            foreach (IZCpTreeViewItem cust in div.Subitems)
            {
                net.sf.mpxj.Task custTask = null;

                if (cust.Subitems.Count > 0)
                {
                    custTask = divTask.addTask();
                    custTask.setName(cust.Name);
                }                    

                //Microsoft.Office.Interop.MSProject.Task custTask = newTask.OutlineChildren.Add(cust.Name);

                //custTask.OutlineLevel = 2;

                foreach (IZCpTreeViewItem contractVm in cust.Subitems)
                {
                    net.sf.mpxj.Task contTask = custTask.addTask();
                    contTask.setName(contractVm.Name);

                    //Microsoft.Office.Interop.MSProject.Task contractTask = custTask.OutlineChildren.Add(contractVm.Name);

                    //contractTask.OutlineLevel = 3;

                    foreach (ZCpProjectViewModel proj in (contractVm as ZCpContractViewModel).Projects)
                    {
                        net.sf.mpxj.Task projTask = contTask.addTask();
                        projTask.setName(proj.Name);

                        //Microsoft.Office.Interop.MSProject.Task projTask = contractTask.OutlineChildren.Add(proj.Project.Name);

                        //projTask.OutlineLevel = 4;

                        foreach (ZCpProjectDetailViewModel detail in proj.ProjectDetail)
                        {
                            net.sf.mpxj.Task projDTask = projTask.addTask();
                            projDTask.setName(detail.ProjectDetail.CostClass);
                            projDTask.setStart(detail.StartDate.HasValue ? new java.util.Date(detail.StartDate.ToString()) : null);

                            //Microsoft.Office.Interop.MSProject.Task projDetailTask = projTask.OutlineChildren.Add(detail.ProjectDetail.CostClass);

                            //projDetailTask.Start = String.Format("{0}", detail.StartDate.ToString());
                            //projDetailTask.Finish = String.Format("{0}", detail.EndDate.ToString());

                            //projDetailTask.OutlineLevel = 5;
                        }
                    }
                }
            }
        }

        net.sf.mpxj.writer.ProjectWriter writer = new MPXWriter();
        writer.write(file, "example.mpx");
    }

The commented out code is the interop code I was using before I found MPXJ. My problem is that after I run this block, my .mpx file has some customers that are blank (even though I put breakpoints in when adding these customers and ensured the names were not empty). Is there something else I need to set to ensure all names are use?

Should I just go back to using the incredibly slow (17 minutes to create ~6000 tasks) interop code. Is there a way to write to the Projcet file using interop without having the Project file open.

Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:42:16+00:00Added an answer on May 24, 2026 at 1:42 am

    Having spoken to Ryan offline, and looked at his data – here is what we found.

    Ryan can generate both MPX and MSPDI files using MPXJ, with a minimal set of attributes for each task. In the example code shown above, just a name and start date are being supplied. All of the task names appear as expected in both the MPX and MSPDI files.

    When opened in Project 2003 or Project 2007, all of the task names are visible… however if you start working through the file and collapsing the task hierarchy (in the case of the data Ryan has generated, collapsing all of the tasks beneath the customer level) occasionally one of the tasks will just be blanked out. All of the data for that task will simply disappear, and no amount of expanding and collapsing the task hierarchy will bring it back.

    The behaviour seems to be worse in Project 2010, where many of the task names are blank as soon as the project loads.

    It looks like this is a weird MS Project issue related to importing files that don’t have certain attributes present. In this case Ryan added a finish date to his export, and that seemed to do the trick. When opened in Project 2010, the files which include the finish date attribute correctly display all of the task names. When opened in Project 2003, I couldn’t reporduce the random “blanking” problem which I saw with the original file.

    On a more general note, there is an example class which ships with MPXJ called MpxjCreate which gives an example of the minimum set of attributes required to ensure that tasks, resources, and resource assignments display as expected when files created with MPXJ are opened in MS Project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.