none
VStudio 2010 / MsProject 2007 / MsProject Interop (Vers. 11.0.0.0) / Application.FileOpen crashes. I cannot open a mpp-file RRS feed

  • Question

  • Dear reader,

    my simple program below crashes at FileOpen with exception "Project cannot open file". Endless searching brought me no idea.

     

    By the way: How can I insert code-snippets here more readable?

     

    Regards

    using

     

    System;

    using

    Microsoft.Office.Interop.MSProject;

    namespace

     

    HackingTest

    {

     

    class

    Program

    {

     

    static void Main(string

    [] args)

    {

     

    Application app = null

    ;

     

    object oMiss = System.Reflection.Missing

    .Value;

     

    String

    fileName = args[0];

    app =

    new Application

    ();

    app.FileOpen(fileName,

    true, oMiss, oMiss, oMiss, oMiss, oMiss, oMiss, oMiss, oMiss, oMiss, PjPoolOpen

    .

    pjPoolReadOnly

     

     

    );

    }

    }

    }

     

    • Moved by Hans.HModerator Friday, September 9, 2011 10:04 AM Moved to the programming forum (From:Project Standard and Professional General Questions and Answers)
    Friday, September 9, 2011 8:45 AM

Answers

  • Shame on me:

    The topic is resolved: Application.FileOpen(...) searches - when no explicit directoryPpath is given - the file in C:\.

     

    But I wanted to open the file in the directory of my executable  :-((

    • Marked as answer by Somigur Wednesday, September 28, 2011 9:54 PM
    Wednesday, September 28, 2011 9:49 PM

All replies

  • Hi Somigur,

    Where are you running this program from? Inside Microsoft Project? Make sure your app is initialized correctly as a Project application.
    When running from inside another application, use

    Dim pj As Object
    
    Set pj = CreateObject("MSProject.Project")
    pj.Application.FileOpen "My Project.mpp"

    Also, make sure the file name is correctly formatted. See the remarks on this page http://msdn.microsoft.com/en-us/library/bb213548(v=office.12).aspx

    And is you file connected to a resource pool file?

    I hope this helps,
    Hans


    My EPM blog: Projectopolis
    Friday, September 9, 2011 10:16 AM
    Moderator
  • Hi Somigur,

    Are you trying to open a project 2003 file in MS project 2007? It seems from MS project Interop version is 11.0.0.0 , Did you try to open a project 2007 file?
    Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82
    Friday, September 9, 2011 11:53 AM
  • Hello to all,

    thank you for your replies, here are my answers

    1) This is a standalone-program ( console-application via C#). I do not run it from inside MsProject

    2) The filename is correct ( because in the full program-version, I check this, before I try to open it with MsProject )

    3) The file is local and not connected to a resource-pool-file

    4) This an MsProject 2007 file. It is NOT a MsProject 2003-File.

     

    Really crazy, so far I had no chance.

     

    PS: The line-spacing of my contributions is so large. Can I decrease this?

     

    Friday, September 9, 2011 12:07 PM
  • You're using VS 2010, so read up about named parameters and optional paramters. It'll help make your code much easier to read and maintain.

    I've found the easiest way to write code for Project is to write it in Excel VBA. Once it works tehn copy the code to your application and convert. Obviously VB is quicker doing this than C#, but do use named and optional parameters. Makes Office automation much easier to maintain.


    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    Saturday, September 10, 2011 2:56 AM
    Moderator
  • Seems, I have some wrong references to the MsProject PIA.

    Here: http://msdn.microsoft.com/en-us/library/15s06t57.aspx   I saw that for MsProject 2007 there are other is Versioin 12.0.0.0 available.

    I tried it, but it also does not work

     

    Saturday, September 10, 2011 8:43 AM
  • Have you implemented Hans instructions?

    Dim pj As Object
    
    Set pj = CreateObject("MSProject.Project")
    pj.Application.FileOpen "My Project.mpp"

    Also, make sure the file name is correctly formatted. See the remarks on this page http://msdn.microsoft.com/en-us/library/bb213548(v=office.12).aspx

     


    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    Saturday, September 10, 2011 8:11 PM
    Moderator
  • Yes I tried it now with Basic: I get "ComException was unhandled" at FileOpen

     

    Good news with really suspicious behavior:

    I'v read documentation and I saw that  with fileName = Type.Missing, a FileOpenDialog should open. But instead, I got a OutOfMemoryException at "app.Fileopen". Then I went to bed yesterday.

     

    Today evening, I started the program again and: It works without any exception ?!?!?!?!?!

    I start with fileName = Type.missing and a FileOpen-Dialog opens as expected.

    I start with fiieName="MyFile" as all the last days and it opens as expected.

     

    I'm puzzled,  the program is selfrepairing over night???

    I seem's, I wanted to vex you, Really, I didn't

    Now I'm waiting what will happen tomorrow

     

    For the moment. many thank you's for your support

     

    Monday, September 12, 2011 7:05 PM
  • Shame on me:

    The topic is resolved: Application.FileOpen(...) searches - when no explicit directoryPpath is given - the file in C:\.

     

    But I wanted to open the file in the directory of my executable  :-((

    • Marked as answer by Somigur Wednesday, September 28, 2011 9:54 PM
    Wednesday, September 28, 2011 9:49 PM