Infragistics XamGantt Control works with a Project instance that contains the task, resource and calendar information for the schedule and has a built in scheduling engine supporting many of the features present in Microsoft Project 2010.
For developers using Infragistics Gantt control will be a challenge to offer an option for data exchange with the established product on the market like Microsoft Project that is the most popular product for project management.
In the previous blog from this series, “Data Exchange with Infragistics XamGantt Control – Using XML (Part 1)” we discussed about how to serialize / deserialize models used for Gantt projects in its own XML format.
In this article we will learn how to collaborate with Microsoft Project .
There are many different approaches to work with MS Project data:
– Using data exchange through files (XML or MS Project format (*. mpp))
– Interact with a Microsoft Project COM-based object model via Office Primary Interop Assemblies (PIA)
We will follow the easiest way for data exchanged based on XamGantt and MS Project features.
When you want your system to exchange data with Microsoft Project you will probably try to exchange data files in MS Project. Infragistics Gantt Control can read projects in MS Project XML format, but for now it does not export data in this format.
Possible solution to export is to have own implementation of the export to MS Project format using the Project XML Data Interchange Schema Reference and mspdi_pj14.xsd schema included in the Project 2010 SDK download.
Let’s create a simple WPF application and add XamGantt control instance inside it. You can start with the samples from my previous post: “How to Start Using Infragistics XamGantt Control” or “Data Exchange with Infragistics XamGantt Control – Using XML (Part 1)”. Add buttons to call import from and export to project.
What you need in advance:
- To have some experience in the use of XML
- To have an experience with MS Office automation and Office Primary Interop Assemblies (PIA).
- To install NetAdvantage for WPF vol. 12.2 or NetAdvantage for Silverlight Vol. 12.2 (these products are also included in NetAdvantage for .NET and NetAdvantage Ultimate)
Import data from Microsoft Project
Infragistics XamGantt control supports out of the box import from Microsoft Project via XML format. It is pretty easy to import projects that you created in MS Project in your application where is used Gantt control.
Let’s create create a new project with Microsoft Project 2010 (you can use also MS Project 2007) and let’s add a few tasks for this project.
Export project data to XML file
You can open XML file in your application as a stream and pass this stream to Project.LoadFromProjectXml method.
Code below shows how to open your XML file.
The code below demonstrates how to use Project.LoadFromProjectXml(Stream) method to create a project in XamGantt control from XML file, exported from MS Project.
You can use standard OpenFileDialog to select the XML file.
The imported in XamlGantt application project seems to have all the features. You can continue to handle data in your application.
Export data to Microsoft Project
Exporting data from XamGantt control to Microsoft Project has more details and is not supported out of the box from Infragistics Gantt component.
An natural choice would be to export data in XML, which is supported by Microsoft Project for data exchange.
The MS Project XML structure is is very complicated. You need to add data, that is not required when you work with XamGantt control. You can create own implementation of the export to MS Project format using the Project XML Data Interchange Schema Reference and mspdi_pj14.xsd schema included in the Project 2010 SDK download.
This approach will take a lot of time. If you need to implement data export faster you can use Microsoft Project COM-based object model. To use the features of a Microsoft Office application from an Office project, you must use the primary interop assembly (PIA) for the application. The PIA enables managed code to interact with a Microsoft Office application’s COM-based object model.
When you install Visual Studio, the PIAs are automatically installed to a location in the file system, outside of the global assembly cache. When you create a new project, Visual Studio automatically adds references to these copies of the PIAs to your project. Visual Studio uses these copies of the PIAs, instead of the assemblies in the global assembly cache, to resolve type references when you develop and build your project.
Visual Studio installs these copies of PIAs to the following locations on the development computer:
%ProgramFiles%\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office12
(or %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office12 on 64-bit operating systems)
%ProgramFiles%\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14
(or %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14 on 64-bit operating systems)
If you have no installed PIA assemblies you could download MS Office 2010 PIA here:
In this sample You will learn how to export data using Office PIA. Unlike the other examples here will demonstrate conjunction with MS Project 2007. Implementation of MS Project 2010 is analogous. The only difference is in referenced assemblies.
You need to have a project with tasks in your XamGantt application.
You need to add reference to Microsoft.Office.Interop.MSProject assembly in your project.
You can use Interop.MSProject with C# or VB.Net to create an MS Project instance, get the active project and in a loop to create MS Project tasks and pass to these objects data from your XamGantt.ProjectTask instances.
That’s it – now you have your data in Microsoft Project! You can implement this very fast and easy – just several lines of code!
It is very easy to exchange data between Gantt projects and MS Project if you know the appropriate approach
- For import use built-in Project.LoadFromProjectXml method
- For export use Microsoft Project COM-based object model via Office Primary Interop Assemblies (PIA)
Follow news from Infragistics for more information about new Infragistics products.
Source code is available here. Sample project is created with Visual Studio 2012, but you can use NetAdvantage 12.2 controls with both: Visual Studio 2012 and Visual Studio 2012. As always, you can follow us on Twitter @mihailmateev and @Infragistics and stay in touch on Facebook, Google+ and LinkedIn!