private void ThisAddIn_Startup(object sender, System.EventArgs e) { //Create Application object MSProject.Application projectApplication = new MSProject.Application(); object missingValue = System.Reflection.Missing.Value; //Open an MPP file projectApplication.FileOpenEx("Project1.mpp", missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, PjPoolOpen.pjPoolReadOnly, missingValue, missingValue, missingValue, missingValue, missingValue); //Create a Project object by assigning active project Project project = projectApplication.ActiveProject; // Enumerate the tasks foreach (Task task in project.Tasks) { //Get critical tasks if (task != null) if ((bool)task.Critical) { Console.WriteLine(task.ID + " " + task.Name); Console.WriteLine(task.Start); Console.WriteLine(task.Finish + "\n"); } } // Make sure to clean up and close the file projectApplication.FileCloseAll(PjSaveType.pjDoNotSave); }
private void ExportToMSProjectButtonClick(object sender, RoutedEventArgs e) { Microsoft.Office.Interop.MSProject.Application msApplication = null; try { msApplication = new Microsoft.Office.Interop.MSProject.Application(); } catch (COMException) { MessageBox.Show("You need to have MSProject installed on your computer in order to use the export functionality of the example.", "No Installation"); return; } try { msApplication.AppMaximize(); msApplication.FileNew(Missing.Value, Missing.Value, Missing.Value, Missing.Value); var msProject = msApplication.ActiveProject; msProject.ManuallyScheduledTasksAutoRespectLinks = false; FillProjectWithTasks(msProject, this.radGanttView1.TasksSource.OfType<IGanttTask>(), null, false); FillTasksWithDependencies(msProject.Tasks.OfType<Task>(), this.radGanttView1.TasksSource.OfType<IGanttTask>()); msApplication.Visible = true; } catch (COMException) { try { msApplication.Quit(PjSaveType.pjDoNotSave); } catch (COMException) { return; } MessageBox.Show("You should not interact with MSProject while Exporting is performed! Please, export again.", "Interaction exception"); } }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { //Create an Application object Microsoft.Office.Interop.MSProject.Application projectApplication = new MSProject.Application(); object missingValue = System.Reflection.Missing.Value; //Open an MPP file projectApplication.FileOpenEx("Project2.mpp", missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, PjPoolOpen.pjPoolReadOnly, missingValue, missingValue, missingValue, missingValue, missingValue); //Create a Project object by assigning active project Microsoft.Office.Interop.MSProject.Project project = projectApplication.ActiveProject; //Create and add new task Microsoft.Office.Interop.MSProject.Task task; task = project.Tasks.Add("Task1", 1); task.Start = "8/23/2012"; task.Duration = 3 * 8 * 60; task.Text1 = "Task1"; //Save project and close application projectApplication.FileCloseAll(Microsoft.Office.Interop.MSProject.PjSaveType.pjSave); }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { //Create an Application object Microsoft.Office.Interop.MSProject.Application projectApplication = new MSProject.Application(); object missingValue = System.Reflection.Missing.Value; //Open an MPP file projectApplication.FileOpenEx("Project1.mpp", missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, PjPoolOpen.pjPoolReadOnly, missingValue, missingValue, missingValue, missingValue, missingValue); Microsoft.Office.Interop.MSProject.Project project = projectApplication.ActiveProject; int iRecourceId = 1; foreach (Task tsk in project.Tasks) { string developer = "Developer0" + iRecourceId; project.Resources.Add(developer, iRecourceId); tsk.Assignments.Add(tsk.ID, iRecourceId, missingValue); iRecourceId++; } projectApplication.FileCloseAll(Microsoft.Office.Interop.MSProject.PjSaveType.pjSave); }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { //Create Application object MSProject. Application projectApplication = new MSProject.Application(); object missingValue = System.Reflection.Missing.Value; //Open an MPP file projectApplication.FileOpenEx("Project1.mpp", missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, PjPoolOpen.pjPoolReadOnly, missingValue, missingValue, missingValue, missingValue, missingValue); //Create a Project object by assigning active project Project project = projectApplication.ActiveProject; //Loop through each task and read information related to tasks foreach (Task task in project.Tasks) { Console.WriteLine("Reading Task " + task.Name); Console.WriteLine("\nID: " + task.ID); Console.WriteLine("Start: " + task.Start); Console.WriteLine("Finish: " + task.Finish); Console.WriteLine("\n===========================\n"); //Read any other information you need } //Loop through each resource and read information related to resources foreach (Resource resource in project.Resources) { string resourceType = null; switch (resource.Type) { case PjResourceTypes.pjResourceTypeCost: resourceType = "Cost"; break; case PjResourceTypes.pjResourceTypeMaterial: resourceType = "Material"; break; case PjResourceTypes.pjResourceTypeWork: resourceType = "Work"; break; } Console.WriteLine("Reading Resource " + resource.Name); Console.WriteLine("\nID: " + resource.ID); Console.WriteLine("Type: " + resourceType); Console.WriteLine("\n===========================\n"); //Read any other information you need } Console.ReadLine(); }
private void CcmRibbon_Load(object sender, RibbonUIEventArgs e) { application = CmmAddIn.thisApp; CmmAddIn.OnProjectLoaded += (project) => { this.project = project; // Update ribbon display var isBuffersHidden = CcmData.GetIsBuffersHidden(); HideUnhideBuffers(isBuffersHidden); }; }
private void ExportToMSProjectButtonClick(object sender, RoutedEventArgs e) { var msApplication = new Microsoft.Office.Interop.MSProject.Application(); msApplication.AppMaximize(); msApplication.FileNew(Missing.Value, Missing.Value, Missing.Value, Missing.Value); var msProject = msApplication.ActiveProject; msProject.ManuallyScheduledTasksAutoRespectLinks = false; FillProjectWithTasks(msProject, this.radGanttView1.TasksSource.OfType<IGanttTask>(), null, false); FillTasksWithDependencies(msProject.Tasks.OfType<Task>(), this.radGanttView1.TasksSource.OfType<IGanttTask>()); msApplication.Visible = true; }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { //Create an Application object Microsoft.Office.Interop.MSProject.Application projectApplication = new MSProject.Application(); object missingValue = System.Reflection.Missing.Value; //Open an MPP file projectApplication.FileOpenEx("Project.mpp", missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, PjPoolOpen.pjPoolReadOnly, missingValue, missingValue, missingValue, missingValue, missingValue); //Create a Project object by assigning active project Microsoft.Office.Interop.MSProject.Project project = projectApplication.ActiveProject; //Add dependencies among the tasks project.Tasks.get_UniqueID(2).TaskDependencies.Add(project.Tasks.get_UniqueID(1), PjTaskLinkType.pjFinishToStart); project.Tasks.get_UniqueID(3).TaskDependencies.Add(project.Tasks.get_UniqueID(2), PjTaskLinkType.pjFinishToStart); project.Tasks.get_UniqueID(4).TaskDependencies.Add(project.Tasks.get_UniqueID(3), PjTaskLinkType.pjFinishToStart); project.Tasks.get_UniqueID(5).TaskDependencies.Add(project.Tasks.get_UniqueID(4), PjTaskLinkType.pjFinishToStart); project.Tasks.get_UniqueID(5).TaskDependencies.Add(project.Tasks.get_UniqueID(2), PjTaskLinkType.pjFinishToStart); //Display the dependencies foreach (Task tsk in project.Tasks) { foreach (TaskDependency dep in project.Tasks.get_UniqueID(tsk.ID).TaskDependencies) { Console.WriteLine("From ID = " + dep.From.ID + "=>To ID = " + dep.To.ID); } Console.WriteLine("____________________________________________________________"); } //Save the project projectApplication.FileCloseAll(Microsoft.Office.Interop.MSProject.PjSaveType.pjSave); }
public CcmData() { application = CmmAddIn.thisApp; project = CmmAddIn.thisApp.ActiveProject; }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { thisApp = Application; this.Application.NewProject += Application_NewProject; }
public static new int Convert(String inputFile, String outputFile, Hashtable options) { Boolean running = (Boolean)options["noquit"]; MSProject.Application app = null; object missing = System.Reflection.Missing.Value; try { try { app = (MSProject.Application)Marshal.GetActiveObject("MSProject.Application"); } catch (System.Exception) { app = new MSProject.Application(); running = false; } System.Type type = app.GetType(); if (type.GetMethod("DocumentExport") == null || System.Convert.ToDouble(app.Version.ToString()) < 14) { Console.WriteLine("Not implemented with Office version {0}", app.Version); return (int)ExitCode.UnsupportedFileFormat; } app.ShowWelcome = false; app.DisplayAlerts = false; app.DisplayPlanningWizard = false; app.DisplayWizardErrors = false; Boolean includeProps = !(Boolean)options["excludeprops"]; Boolean markup = (Boolean)options["markup"]; FileInfo fi = new FileInfo(inputFile); switch(fi.Extension) { case ".mpp": MSProject.Project project = null; if (app.FileOpenEx(inputFile, false, MSProject.PjMergeType.pjDoNotMerge,missing, missing, missing, missing, missing, missing, missing, missing, MSProject.PjPoolOpen.pjDoNotOpenPool, missing, missing, false, missing)) { project = app.ActiveProject; } if (project == null) { return (int)ExitCode.UnknownError; } app.DocumentExport(outputFile, MSProject.PjDocExportType.pjPDF, includeProps, markup, false, missing, missing); app.FileCloseEx(MSProject.PjSaveType.pjDoNotSave, missing, missing); break; } return File.Exists(outputFile) ? (int)ExitCode.Success : (int)ExitCode.UnknownError; } catch (System.Exception e) { Console.WriteLine(e.Message); return (int)ExitCode.UnknownError; } finally { if (app != null && !running) { ((MSProject.Application)app).Quit(); } Converter.releaseCOMObject(app); } }
private void LaunchMSProject() { try { this.application = new MSProject.Application(); application.Visible = true; System.Threading.Thread.Sleep(5000); application.Projects.Add(System.Type.Missing, System.Type.Missing, System.Type.Missing); this.project = this.application.ActiveProject; this.SetCalendarNoHolidays(); this.launched = true; #region Example code from http://social.technet.microsoft.com/Forums/ru-RU/project2010custprog/thread/0d4b2b34-3051-4b27-bb51-e3cae64ac9f9 //bool launched = false; //for (int timerSec = 0; timerSec < 20 && !launched; timerSec++) //{ // try // { // this.application.WorkOffline(false); // launched = true; // break; // } // catch // { // } //} //if (!launched) //{ // application.DocClose(); // System.Threading.Thread.Sleep(1500); // application.Quit(MSProject.PjSaveType.pjDoNotSave); // throw new ApplicationException("Unable to start an instance of MS Project"); //} #endregion } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }