none
ProjectIDInvalid Error when creating project programmatically RRS feed

  • Question

  • Hi,

    Here's the code and it's generating an error "ProjectIDInvalid".  Maybe need another set of eyes to look at this.

            try
                {
                    Project nProject = new Project();
                    ProjectDataSet dsProject = new ProjectDataSet();
                    ProjectDataSet.ProjectRow newRow = dsProject.Project.NewProjectRow();
                    Guid newID = new Guid();

                    newRow.PROJ_UID = newID;
                    newRow.PROJ_NAME = pProjectName;
                    newRow.PROJ_TYPE = 0;
                    newRow.PROJ_INFO_START_DATE = DateTime.Now;

                    // my project type, obtained from URL when creating new project in project server
                    newRow.ENTERPRISE_PROJECT_TYPE_UID = new Guid("351a8582-0fa9-4d6f-99f5-98a790a2957e");

                    newRow.ENTERPRISE_PROJECT_TYPE_NAME = pProjectName;

                    dsProject.Project.AddProjectRow(newRow);

                    //Valid cookie has been provided
                    nProject.CookieContainer = GetLogonCookie();

                    nProject.QueueCreateProject(Guid.NewGuid(), dsProject, false);
                    nProject.QueuePublish(Guid.NewGuid(), newID, true, string.Empty);

                    return newID.ToString();
                }
                catch (Exception ex)
                {
                    string errMsg = "";

                    if (ex.GetType().Equals(typeof(SoapException)))
                    {
                        PSLib.PSClientError psiError = new PSLib.PSClientError((SoapException)ex);
                        PSLib.PSErrorInfo[] psiErrors = psiError.GetAllErrors();

                        for (int j = 0; j < psiErrors.Length; j++)
                        {
                            errMsg += psiErrors[j].ErrId.ToString() + "\n";
                        }
                    }
                    else
                        errMsg = ex.Message;

                    return errMsg;
                }

    Your help is always appreciated.  Thanks,


    kashif

    Wednesday, July 18, 2012 3:37 PM

Answers

  •                 Project nProject = new Project();
                    ProjectDataSet dsProject = new ProjectDataSet();
                    ProjectDataSet.ProjectRow newRow = dsProject.Project.NewProjectRow();
                    Guid newID = new Guid();

                    newRow.PROJ_UID = newID;
                     ...

                    nProject.QueueCreateProject(Guid.NewGuid(), dsProject, false);
                    nProject.QueuePublish(Guid.NewGuid(), newID, true, string.Empty);

                    ...


    kashif

    Hi,

    An update:  By changing the bold marked text from Guid newID = new Guid() to Guid newID = Guid.NewGuid(), it generated a GUID which allowed me to create the project.  but now, i am getting "GeneralSecurityAccessDenied" on QueuePublish.  when i look in server settings -> delete enterprise objects, i can see the project created but since it failed on publish, it is not available in Project Center.  Any ideas.  Thanks for the help!

    Regards,


    kashif


    Thursday, July 19, 2012 1:33 PM
  • Hi,

    An update:  It was that the user I was using had access to create the project but not publish it.  So I used the admin account used to create PWA site and voila it works!

    Happy Coding!


    kashif

    Thursday, July 19, 2012 2:47 PM

All replies

  •                 Project nProject = new Project();
                    ProjectDataSet dsProject = new ProjectDataSet();
                    ProjectDataSet.ProjectRow newRow = dsProject.Project.NewProjectRow();
                    Guid newID = new Guid();

                    newRow.PROJ_UID = newID;
                     ...

                    nProject.QueueCreateProject(Guid.NewGuid(), dsProject, false);
                    nProject.QueuePublish(Guid.NewGuid(), newID, true, string.Empty);

                    ...


    kashif

    Hi,

    An update:  By changing the bold marked text from Guid newID = new Guid() to Guid newID = Guid.NewGuid(), it generated a GUID which allowed me to create the project.  but now, i am getting "GeneralSecurityAccessDenied" on QueuePublish.  when i look in server settings -> delete enterprise objects, i can see the project created but since it failed on publish, it is not available in Project Center.  Any ideas.  Thanks for the help!

    Regards,


    kashif


    Thursday, July 19, 2012 1:33 PM
  • Hi,

    An update:  It was that the user I was using had access to create the project but not publish it.  So I used the admin account used to create PWA site and voila it works!

    Happy Coding!


    kashif

    Thursday, July 19, 2012 2:47 PM