none
Is there any way to save a copy of the schedule on Published event using PSI/CSOM in Project Server 2016 RRS feed

  • Question

  • Hi,

    Wanted to  save a copy of the schedule on on the shared path location on each publish of a Project as per the client requirement. Have achieved it using VB macro from MPP, but I'm looking to implement this from the server side event handler. The reason for this is, Managers can publish the project from either MPP or PWA, so the solution should capture the copy of the schedule from either ways.

    Is there a way to save a copy of the schedule using PSI/CSOM?

    Any help would be very much appreciated.

    Thanks.




    Wednesday, February 7, 2018 6:50 AM

Answers

  • Hello,

    There aren't any methods in the PSI / CSOM to save a project as an MPP file as this is a Project client feature. You could automate the Project client using Office Interop:

    https://msdn.microsoft.com/en-us/library/bb772083.aspx

    Not what you are trying to do but would give you a good starter: https://epmxperts.wordpress.com/2010/12/15/using-ms-project-interop-assembly-to-save-mpp-file-as-template/

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads

    Wednesday, February 7, 2018 9:20 AM
    Moderator
  • Hi Paul,

    Thanks for your reply,  have achieved it using Project client using Office Interop: 

    Here is the sample code, it might help some one. The below code launches MS Project client and will directly connect to the Server and opens the specified project followed by save a copy at the specified path location then close the application.

    Note: Make sure to add the below namespaces.

    using System.Diagnostics;
    using System.Reflection;
    using System.Threading;

    using Microsoft.Office.Interop.MSProject;

    ==================

     string PWAUrl = "<PWA URL>";
                string ProjectName = <ProjectName>;(You can read the project name dynamically from the server)

                string paramList = " /s " + PWAUrl;
                var startInfo = new ProcessStartInfo("C:\\Program Files\\Microsoft Office\\Office16\\WINPROJ.EXE", paramList);
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.UseShellExecute = false;
                Process.Start(startInfo);
                Thread.Sleep(1000);

                try
                {
                    string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
                    ApplicationClass ProjectApp = new ApplicationClass();
                    string currentProject = "<>\\" + ProjectName;
                    ProjectApp.FileOpen(currentProject, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, PjPoolOpen.pjDoNotOpenPool, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                    Thread.Sleep(3000);
                    ProjectApp.WindowHide();
                    ProjectApp.FileSaveAs(@"C:\Raj\" + ProjectName + "_" + timestamp, PjFileFormat.pjMPP, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true, true, true, true, Type.Missing, true);
                    Thread.Sleep(2000);
                    //close the MS Project Client
                    ProjectApp.FileCloseEx(PjSaveType.pjDoNotSave, false, !ProjectApp.ActiveProject.ReadOnly);
                    ProjectApp.Quit(PjSaveType.pjDoNotSave);
                    ProjectApp = null;
                }
                catch (System.Exception Ex)
                {
                    MessageBox.Show(Ex.Message + Ex.StackTrace);
                }
                MessageBox.Show("Project : " + ProjectName + " was Saved successfully");

            }



    Thursday, February 8, 2018 3:43 AM

All replies

  • Hello,

    There aren't any methods in the PSI / CSOM to save a project as an MPP file as this is a Project client feature. You could automate the Project client using Office Interop:

    https://msdn.microsoft.com/en-us/library/bb772083.aspx

    Not what you are trying to do but would give you a good starter: https://epmxperts.wordpress.com/2010/12/15/using-ms-project-interop-assembly-to-save-mpp-file-as-template/

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads

    Wednesday, February 7, 2018 9:20 AM
    Moderator
  • Hi Paul,

    Thanks for your reply,  have achieved it using Project client using Office Interop: 

    Here is the sample code, it might help some one. The below code launches MS Project client and will directly connect to the Server and opens the specified project followed by save a copy at the specified path location then close the application.

    Note: Make sure to add the below namespaces.

    using System.Diagnostics;
    using System.Reflection;
    using System.Threading;

    using Microsoft.Office.Interop.MSProject;

    ==================

     string PWAUrl = "<PWA URL>";
                string ProjectName = <ProjectName>;(You can read the project name dynamically from the server)

                string paramList = " /s " + PWAUrl;
                var startInfo = new ProcessStartInfo("C:\\Program Files\\Microsoft Office\\Office16\\WINPROJ.EXE", paramList);
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.UseShellExecute = false;
                Process.Start(startInfo);
                Thread.Sleep(1000);

                try
                {
                    string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
                    ApplicationClass ProjectApp = new ApplicationClass();
                    string currentProject = "<>\\" + ProjectName;
                    ProjectApp.FileOpen(currentProject, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, PjPoolOpen.pjDoNotOpenPool, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                    Thread.Sleep(3000);
                    ProjectApp.WindowHide();
                    ProjectApp.FileSaveAs(@"C:\Raj\" + ProjectName + "_" + timestamp, PjFileFormat.pjMPP, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true, true, true, true, Type.Missing, true);
                    Thread.Sleep(2000);
                    //close the MS Project Client
                    ProjectApp.FileCloseEx(PjSaveType.pjDoNotSave, false, !ProjectApp.ActiveProject.ReadOnly);
                    ProjectApp.Quit(PjSaveType.pjDoNotSave);
                    ProjectApp = null;
                }
                catch (System.Exception Ex)
                {
                    MessageBox.Show(Ex.Message + Ex.StackTrace);
                }
                MessageBox.Show("Project : " + ProjectName + " was Saved successfully");

            }



    Thursday, February 8, 2018 3:43 AM
  • Good to hear you have resolved it and thank you for sharing the code.

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS | MVP | Downloads

    Thursday, February 8, 2018 9:55 AM
    Moderator