Reading ms project files

Coordinator
Oct 2, 2013 at 8:18 AM
  1. Download and reference the mpjx files in your project.
  2. Define a sub and have this inside...
strfile is the full path of your project file (we are doing microsoft project)

....
Dim reader As ProjectReader = ProjectReaderUtility.getProjectReader(strFile)
        Dim mpx As net.sf.mpxj.ProjectFile = reader.read(strFile)
        ExportTasks(mpx)
...

The ExportTasks method is inside the source code file.

The table definition is below. Please adjust it for your own code as this is my example...

Public Shared Sub CreateTable()
    Dim flag As Boolean = SQLCompact.Table_Exists("Ms_project")
    If flag = True Then Exit Sub
    Dim strQRY as string = ""
    strQRY = "CREATE TABLE [Ms_project] ([Id] int NOT NULL , [ParentId] int NULL , [Guid] nvarchar(100) NULL , [UniqueId] int NULL , [Start] datetime NULL , [Finish] datetime NULL , [Duration] nvarchar(100) NULL , [OutlineLevel] int NULL , [OutlineNumber] nvarchar(100) NULL , [PercentageComplete] float NULL , [ActualStart] datetime NULL , [ActualFinish] datetime NULL , [BaselineStart] datetime NULL , [BaselineFinish] datetime NULL , [ActualDuration] nvarchar(100) NULL , [ConstraintDate] datetime NULL , [ConstraintType] nvarchar(100) NULL , [Critical] nvarchar(100) NULL , [EarlyFinish] datetime NULL , [EarlyStart] datetime NULL , [Estimated] nvarchar(100) NULL , [TotalSlack] nvarchar(100) NULL , [LateFinish] datetime NULL , [LateStart] datetime NULL , [Milestone] nvarchar(100) NULL , [Name] nvarchar(255) NULL , [Notes] ntext NULL , [Predecessors] nvarchar(100) NULL , [Successors] nvarchar(100) NULL , [RemainingWork] nvarchar(100) NULL , [RemainingCost] float NULL , [Cost] float NULL , [CostVariance] float NULL , [FreeSlack] nvarchar(100) NULL , [StartSlack] nvarchar(100) NULL , [FinishSlack] nvarchar(100) NULL , [RemainingDuration] nvarchar(100) NULL , [ResourceNames] ntext NULL , [Summary] nvarchar(100) NULL , [WBS] nvarchar(100) NULL , [Work] nvarchar(100) NULL );"
    SQLCompact.RunQuery(strQRY, True)
    SQLCompact.RunQuery("ALTER TABLE [Ms_project] ADD CONSTRAINT [Ms_project_PK] PRIMARY KEY ([Id]);", True)
    SQLCompact.RunQuery("CREATE INDEX [Id] ON [Ms_project] ([Id] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [ParentId] ON [Ms_project] ([ParentId] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [Guid] ON [Ms_project] ([Guid] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [UniqueId] ON [Ms_project] ([UniqueId] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [Start] ON [Ms_project] ([Start] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [Finish] ON [Ms_project] ([Finish] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [Duration] ON [Ms_project] ([Duration] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [OutlineLevel] ON [Ms_project] ([OutlineLevel] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [OutlineNumber] ON [Ms_project] ([OutlineNumber] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [PercentageComplete] ON [Ms_project] ([PercentageComplete] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [ActualStart] ON [Ms_project] ([ActualStart] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [ActualFinish] ON [Ms_project] ([ActualFinish] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [BaselineStart] ON [Ms_project] ([BaselineStart] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [BaselineFinish] ON [Ms_project] ([BaselineFinish] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [ActualDuration] ON [Ms_project] ([ActualDuration] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [ConstraintDate] ON [Ms_project] ([ConstraintDate] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [ConstraintType] ON [Ms_project] ([ConstraintType] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [Critical] ON [Ms_project] ([Critical] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [EarlyFinish] ON [Ms_project] ([EarlyFinish] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [EarlyStart] ON [Ms_project] ([EarlyStart] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [Estimated] ON [Ms_project] ([Estimated] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [TotalSlack] ON [Ms_project] ([TotalSlack] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [LateFinish] ON [Ms_project] ([LateFinish] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [LateStart] ON [Ms_project] ([LateStart] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [Milestone] ON [Ms_project] ([Milestone] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [Name] ON [Ms_project] ([Name] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [Summary] ON [Ms_project] ([Summary] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [WBS] ON [Ms_project] ([WBS] ASC);", True)
    SQLCompact.RunQuery("CREATE INDEX [Work] ON [Ms_project] ([Work] ASC);", True)
End Sub
Enjoy...