none
Add and Set Customer Property for Microsoft Project RRS feed

  • Question

  • I am using Visual Studio 2008 Pro and Microsoft Office Project Pro 2003

    In my VB.NET code i want to
    a. Check if a given Custom Property exists
    b. If not then create the Custom Property
    c. Assign text value to this property

    Here's my code:

    MSPrjApp = New MSProject.Application
    MSPrjApp.FileOpen(C:\file1.mpp)
    MSPrjProject = MSPrjApp.ActiveProject()
    
    Dim oBuiltInProps As Object
    Dim oCustomProps As Object
    
    oBuiltInProps = MSPrjProject.BuiltinDocumentProperties
    oCustomProps = MSPrjProject.CustomDocumentProperties

    If a custom property was already set in the mpp (say 'Database') then i can get it's value as

    oCustomProps.Item("Database").Value.ToString()

    and i can also set it's value by

    oCustomProps.Item("Database").Value = "QWERTY"

    The problem, is when this property doesn't already exist in the MPP file

    How do i check if it already exists and create if it doesn't?
    How can i get list of all custom Properties?

    The CustomDocumentProperties() returns type Object and not Collection type

    Public Overridable ReadOnly Property CustomDocumentProperties() As Object
         Member of MSProject.ProjectClass

    Thanks,

    -srinivas yelamanchili



    • Edited by ysrini Sunday, June 10, 2012 7:09 PM
    Sunday, June 10, 2012 6:47 PM

All replies

  • Hi ysrini,

    Based on your issue ,I would suggest the following solution  to you respectively.

    1. If you check a custom property already exists and create if it doesn't,please try this http://msdn.microsoft.com/en-us/library/dhxe2d75(v=vs.90).aspx. You can modify the TestProperties() method cast to your code.
    2. You can get the custom properties collection from the CustomProperties property refers to http://msdn.microsoft.com/en-us/library/ff862912

    Thanks,

    Leo

    Monday, June 11, 2012 3:21 AM
  • Hi Leo,
    I studied both the articles. I am using Visual C# 2010 and have Microsoft Project 2003 on my computer.
    I added the namespaces Microsoft.Office.Interop.MSProject and Microsoft.Office.Core to my code

    I can't seem to use 'Office.DocumentProperties' in my code as in http://msdn.microsoft.com/en-us/library/dhxe2d75%28v=vs.100%29.aspx
    How do i get this to work?

    Thanks,
    -sri


    sri

    Thursday, June 21, 2012 3:15 PM