Hello,
I am using:
Visual Studio 2010 10.0.30319.1
MS Project Professional 2010 14.0.6112.5000 (32-bit)
I am trying to set the AvailableFrom field of a Resource from a MSProject planning with the following piece of C# code:
using System; using System.Collections.Generic; using System.Text; using System.Collections; using MSProject = Microsoft.Office.Interop.MSProject; using System.IO; using System.Runtime.InteropServices; namespace PlanningsSprint { class MSProjectPlanningResources { public string InputFilename { get; set; } static int Main(string[] args) { MSProjectPlanningResources process = new MSProjectPlanningResources(); process.InputFilename = "c:\\temp\\VS2010\\Project.mpp"; process.Process(); return 0; } public void Process() { try { MSProject.Application msProjectApplication = new MSProject.Application(); msProjectApplication.FileOpenEx(InputFilename); MSProject.Resource resource = msProjectApplication.ActiveProject.Resources["ResourceName"]; resource.AvailableFrom = new DateTime(2012, 1, 1); Console.ReadLine(); } catch (Exception e) { Console.Error.WriteLine(e); Console.ReadLine(); } } } }
It permanently fails with this exception:
System.Runtime.InteropServices.COMException (0x800A044D): The argument value is not valid.
at Microsoft.Office.Interop.MSProject.Resource.set_AvailableFrom(Object retval)
at PlanningsSprint.MSProjectPlanningResources.Process() in C:\Users\pdavid\Documents\SkyDrive\Visual Studio 2010\Projects\VS2010\MSProjectPlanningResources.cs:line 34
How can I fix this?
Patrick