none
MS Project Object Model

    Question

  • Hi,

    I have a .MPP file created using MS Project 2003. Now, I need to read the tasks in it (through my code) and create work items corrsponding to each task (again through my code).
     i.e. I want to do the same functionality that the 'Publish' button on Team toolbar in MS Project 2003 does.

    Is there any object model/SDK/APIs to read the contents of .MPP file?

    Manasi
    Wednesday, February 14, 2007 6:01 AM

Answers

  • Found the solution. Downloaded the primary interop assemblies from this link: www.microsoft.com/downloads/details.aspx?familyid=3c9a983a-ac14-4125-8ba0-d36d67e0f4ad&displaylang=en

    In .NET project added reference to 'Microsoft Project 11.0 Object Library' in COM tab of Add Reference dialog box.

    In code added following line: using MSProject = Microsoft.Office.Interop.MSProject;
    Used following code to extract information from mpp file

    --------------------------------------------------------------------------------------------
        public string Load(string fileName)
            {
                MSProject.ApplicationClass app = null;
                string retVal = "";    
                ArrayList tasks = new ArrayList();
                         
                try
                {
                    // execute the Microsoft Project Application
                    app = new MSProject.ApplicationClass();

                    // Do not display Microsoft Project
                    app.Visible = false;
                   
                    // open the project file.
                    if(app.FileOpen(fileName, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, MSProject.PjPoolOpen.pjPoolReadOnly, Type.Missing, Type.Missing, Type.Missing, Type.Missing))
                    {                   
                        // go through all the open projects--there should only be one
                        foreach(MSProject.Project proj in app.Projects)
                        {                       
                            // go through all the tasks in the project
                            foreach(MSProject.Task task in proj.Tasks)
                            {                     
                                    // add Microsoft Project Task to arraylist                          
                                    tasks.Add(new Task(task));
                            }
                        }
                    }
                    else
                    {
                        retVal = "The MS Project file " + fileName + " could not be opened.";
                    }
                }
                catch (Exception ex)
                {
                    retVal =  "Could not process the MS Project file " + fileName + "." + System.Environment.NewLine +  ex.Message + System.Environment.NewLine + ex.StackTrace;
                }

                // close the application if is was opened.
                if(app != null)
                {
                    app.Quit(MSProject.PjSaveType.pjDoNotSave);
                }
                return retVal;
            }
    --------------------------------------------------------------------------------------------
    Friday, February 16, 2007 12:25 PM

All replies

  • Few links which has information related to MPP API are :

    http://www.aspose.com/Products/Aspose.Tasks/Api/Aspose.Tasks.MPPFile.html

    http://hearwhat.blogspot.com/2004_03_01_hearwhat_archive.html#108028565677237750

    Second one seems to be using better approach. It uses OLEDB provider fo MS project.

    Hope this will help.

     

    Wednesday, February 14, 2007 9:07 AM
  • Found the solution. Downloaded the primary interop assemblies from this link: www.microsoft.com/downloads/details.aspx?familyid=3c9a983a-ac14-4125-8ba0-d36d67e0f4ad&displaylang=en

    In .NET project added reference to 'Microsoft Project 11.0 Object Library' in COM tab of Add Reference dialog box.

    In code added following line: using MSProject = Microsoft.Office.Interop.MSProject;
    Used following code to extract information from mpp file

    --------------------------------------------------------------------------------------------
        public string Load(string fileName)
            {
                MSProject.ApplicationClass app = null;
                string retVal = "";    
                ArrayList tasks = new ArrayList();
                         
                try
                {
                    // execute the Microsoft Project Application
                    app = new MSProject.ApplicationClass();

                    // Do not display Microsoft Project
                    app.Visible = false;
                   
                    // open the project file.
                    if(app.FileOpen(fileName, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, MSProject.PjPoolOpen.pjPoolReadOnly, Type.Missing, Type.Missing, Type.Missing, Type.Missing))
                    {                   
                        // go through all the open projects--there should only be one
                        foreach(MSProject.Project proj in app.Projects)
                        {                       
                            // go through all the tasks in the project
                            foreach(MSProject.Task task in proj.Tasks)
                            {                     
                                    // add Microsoft Project Task to arraylist                          
                                    tasks.Add(new Task(task));
                            }
                        }
                    }
                    else
                    {
                        retVal = "The MS Project file " + fileName + " could not be opened.";
                    }
                }
                catch (Exception ex)
                {
                    retVal =  "Could not process the MS Project file " + fileName + "." + System.Environment.NewLine +  ex.Message + System.Environment.NewLine + ex.StackTrace;
                }

                // close the application if is was opened.
                if(app != null)
                {
                    app.Quit(MSProject.PjSaveType.pjDoNotSave);
                }
                return retVal;
            }
    --------------------------------------------------------------------------------------------
    Friday, February 16, 2007 12:25 PM
  • How can i add new task without taking care of index using c# .For when i try to add new task the method takes two parameters the task name and second is the location (index value of the task) . Is there any way i can add task with parent/child scenarios.
    Friday, June 15, 2007 6:27 AM
  • How can i add task in parent/child scenario. while adding task using the method "add" , it takes 2 parameters ,task name and index value. I dont want to use index value rather i want to add task with respect to parent .I am using MSProject in C# ...

    Regards
    Friday, June 15, 2007 6:30 AM
  • Hi,

     

    I work on the TFS Office integration team and trying to understand your requirements.

     

    Can you provide some details on the scenarios you are planning to address using your Project Add-in? Are these scenarios like Parent/Child , Predecessor/Successor links that are not supported by TFS Project Add-in?

     

    The best place to look for Project API related help is the VBA help that ships with Project. From Project use Alt+F11 to open the VBA editor and use the help (F1) in that editor. These APIs are exposed to managed code using Project Primary Interop assembly

     

    Following is a sample macro that shows how to add parent/subtask

    Sub AddTasks()
        Application.ActiveProject.Tasks.Add ("Parent Task")
        Application.ActiveProject.Tasks.Add("Sub Task").OutlineIndent
        Application.ActiveProject.Tasks.Add("Another toplevel Task").OutlineOutdent
    End Sub

     

    Swamy

    Tuesday, June 19, 2007 9:48 PM
  • Hi Swamy,

    I'm afraid I'm having a similar problem which is not yet answered by your post. How do I actually get the current TeamFoundationServer instance or the name of the current TFS out of the MS Project Addin?

    Best regards,

    Sven
    Wednesday, September 17, 2008 5:38 PM
  • I have developed a test app in .NET that reads an MPP file. It just iterates thru' the available nodes and shows them as a list, like such:

            ' Open the file. There are a number of options in this constructor as you can see
            Dim proj As Project = projectApp.ActiveProject

            For Each p As System.Reflection.PropertyInfo In proj.GetType().GetProperties()
                If p.CanRead Then
                    Try
                        Console.WriteLine("{0}: {1}", p.Name, p.GetValue(proj, Nothing))
                        Dim item As RadListBoxItem = New RadListBoxItem
                        item.Name = p.Name
                        item.Text = p.Name
                        item.Value = p.GetValue(proj, Nothing)
                        lbNodes.SelectedIndex = 0

                        If blnComboboxItemSelected = False Then
                            lbNodes.SelectedItem = p.Name
                            blnComboboxItemSelected = True
                        End If
                        lbNodes.Items.Add(item)
                    Catch ex As Exception
                    End Try
                End If
            Next

    This works in XP Pro. I am able to see the "Task" node. However, it is missing in Windows 7 Pro x64.

    Wednesday, February 24, 2010 6:30 PM