I need to save local copies of all my projects stored in my PWA instance at Microsoft Project Online frequently. I have hundreds of them so doing it manually is not an option.
I've been able to connect to the PWA instance with Project Server CSOM and .NET and read the data. But I couldn't find a way within the Microsoft.ProjectServer.Client
namespace to export this data and save it locally to any MS Project-readable file.
Is this even possible at all?
Alternatively, any other way to achieve this not involving the Project Server CSOM would be welcome.
Edit: I've also tried to obtain the data through the Project Online REST API, so I can get a XML file that I could use as if it were a MSPDI file. But neither MS Project Professional (the desktop application) nor MPXJ library recognize it, I might need to do some heavy transformation and that doesn't guarantee it will even work...
In the end I decided to go the "ugly but working" way, directly telling MS Project desktop client to connect, open and locally save the project, with some C# code:
private static void start()
{
var objProcess = Process.Start(@"winproj.exe", "/s https://PWA-URL");
}
static void Main(string[] args)
{
var backgroundThread = new Thread(new ThreadStart(start));
backgroundThread.Start();
Thread.Sleep(10000);
ApplicationClass objProject = new ApplicationClass
{
Visible = false
};
object oMissing = System.Reflection.Missing.Value;
object oFile = @"<>\test-project";
object oFormat = "MSProject.mpp";
object oReadOnly = true;
objProject.DisplayAlerts = false;
objProject.FileOpen(oFile, oReadOnly, PjMergeType.pjDoNotMerge, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oFormat, oMissing, PjPoolOpen.pjPoolReadOnly, oMissing, oMissing, oMissing, oMissing);
objProject.FileSaveAs(@"C:\Windows\Temp\LocalCopy.mpp");
objProject.Quit(PjSaveType.pjDoNotSave);
}
Windows Credentials are used to connect to the PWA, although different user and password could specified but I haven't tried (ApplicationClass.FileOpen).
One should also import Microsoft.Office.Interop.MSProject.dll to compile the project.