none
C# Add-In for MS Project 2010 selected Tasks and using custom properties of a file RRS feed

  • Question

  • Hello,

    1.,

    I have just a little problem. I am writing in c# an add in for MS Projects 2010 and need to get the title, start- and enddate of tasks, which get selected (multiple) of the user in the active project.

    2.,

    I need to create a customer propertie field of a project file "SP_URL" and get the content out of it if (!= null) or write a weblink inside.

    Does anybody could help me?


    • Edited by Becksteiner Wednesday, December 17, 2014 1:28 PM
    Tuesday, December 16, 2014 3:01 PM

Answers

  • Globals.ThisAddIn.Application.ActiveSelection.Tasks[0]

    • Marked as answer by Becksteiner Wednesday, January 7, 2015 9:57 AM
    Monday, December 22, 2014 6:08 AM
  • Hello,

    Thank you for your help:

    I managed it this way:

    List<ProxyTask> tasks = new List<ProxyTask>();

    Selection s = ThisAddIn.ProjectApplication.ActiveSelection;
                Tasks prTasks = s.Tasks;
                foreach (Task t in prTasks)
                {
                    ProxyTask newItem = new ProxyTask();
                    newItem.Title = t.Name;
                    ...
                    tasks.Add(newItem);
                 }

                ReleaseComObject(prTasks);
                return tasks;

    • Marked as answer by Becksteiner Wednesday, January 7, 2015 10:04 AM
    Wednesday, January 7, 2015 10:04 AM

All replies

  • That's the way to do it. Create a VBA solution then convert to C# or VB.Net. Obviously converting to VB is quicker!

    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Wednesday, December 17, 2014 8:32 AM
    Moderator
  • Hello, I am sorry, but this is not working. Because the Object ActiveSelection.T is not the same as in c#. I would need a method for c# to get the selected Tasks.

    Do you have an idea?

    best regards, robert

    Wednesday, December 17, 2014 12:40 PM
  • Start with the application object then look for an activeselection like object.

    Develop the solution in VBA first because if VBA can't do it neither can C# or VB.Net. Translating to VB.Net is very quick and easy. Translating to C# is harder. Strongly recommend VS 2010 or later as it allows optional parameters and named parameters which make for much easier to read, understand and maintain code. (= quicker and cheaper). If you have an older version of VS, do it in VB.

    I've found that VSTO does have some properties and objects that don't work properly (same as VBA) C# more than VB.Net so you may have stumbled on one of the stumbling blocks. If necessary just do this bit in VB.Net or call a VBA macro to do the work.


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Thursday, December 18, 2014 5:08 AM
    Moderator
  • Globals.ThisAddIn.Application.ActiveSelection.Tasks[0]

    • Marked as answer by Becksteiner Wednesday, January 7, 2015 9:57 AM
    Monday, December 22, 2014 6:08 AM
  • Hello,

    Thank you for your help:

    I managed it this way:

    List<ProxyTask> tasks = new List<ProxyTask>();

    Selection s = ThisAddIn.ProjectApplication.ActiveSelection;
                Tasks prTasks = s.Tasks;
                foreach (Task t in prTasks)
                {
                    ProxyTask newItem = new ProxyTask();
                    newItem.Title = t.Name;
                    ...
                    tasks.Add(newItem);
                 }

                ReleaseComObject(prTasks);
                return tasks;

    • Marked as answer by Becksteiner Wednesday, January 7, 2015 10:04 AM
    Wednesday, January 7, 2015 10:04 AM