Click here to Skip to main content
11,632,260 members (90,128 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
I added office 2010 MS project in my solution and below code is generated, how can I call this code on button click
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using MSProject = Microsoft.Office.Interop.MSProject;
using Office = Microsoft.Office.Core;
 
namespace FirstProjectAddIn
{
    public partial class ThisAddIn
    {
 
      public   void Application_NewProject(Microsoft.Office.Interop.MSProject.Project pj)
        {
            MSProject.Task newTask = pj.Tasks.Add
                ("This text was added by using code", missing);
            newTask.Start = DateTime.Now;
            newTask.Duration = "3";
            newTask.ResourceNames = "MAnoj, Kelly Krout";
        }
 
        public  void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
           // this.Application.NewProject += new Microsoft.Office.Interop.MSProject._EProjectApp2_NewProjectEventHandler(Application_NewProject);

        }
 
        public void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }
 
        #region VSTO generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}
Posted 14-Nov-12 23:33pm
Edited 14-Nov-12 23:41pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try something like this.
//...
    FirstProjectAddIn.ThisAddIn addin = new FirstProjectAddIn.ThisAddIn();
    Microsoft.Office.Interop.MSProject.Application prj_app = new Microsoft.Office.Interop.MSProject.ApplicationClass();
    if (prj_app != null){
        prj_app.Visible = false; // Make MS Project application invisible
        // ... create new or load existing project
        Microsoft.Office.Interop.MSProject.Project p = new Microsoft.Office.Interop.MSProject.Project();
        addin.Application_NewProject(p);
        //...
        // exiting app
        prj_app.Quit(Microsoft.Office.Interop.MSProject.PjSaveType.pjSave);
    }
//...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,498
1 Sergey Alexandrovich Kryukov 8,149
2 Mika Wendelius 6,260
3 F-ES Sitecore 2,321
4 Suvendu Shekhar Giri 1,995


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100