Creating a Project Online using C# for Sharepoint

2019-07-31 08:40发布

Right, I have a working bit of code which allows me to create a Sharepoint Project Online, however it is creating as an "Enterprise Project" by default, I want to create, it as a "SharePoint Tasks List" instead. (these are the 2 options below when editing the project online)

enter image description here

The only bit of code I have managed to find is this to change it:

// Get the GUID of the specified enterprise project type.
        private static Guid GetEptUid(string eptName)
        {
            Guid eptUid = Guid.Empty;

            try
            {
                // Get the list of EPTs that have the specified name. 
                // If the EPT name exists, the list will contain only one EPT.
                var eptList = projContext.LoadQuery(
                    projContext.EnterpriseProjectTypes.Where(
                        ept => ept.Name == eptName));
                projContext.ExecuteQuery();

                eptUid = eptList.First().Id;

                // Alternate routines to find the EPT GUID. Both (a) and (b) download the entire list of EPTs.
                // (a) Using a foreach block:
                //foreach (EnterpriseProjectType ept in projSvr.EnterpriseProjectTypes)
                //{
                //    if (ept.Name == eptName)
                //    {
                //        eptUid = ept.Id;
                //        break;
                //    }
                //}
                // (b) Querying for the EPT list, and then using a lambda expression to select the EPT:
                //var eptList = projContext.LoadQuery(projContext.EnterpriseProjectTypes);
                //projContext.ExecuteQuery();
                //eptUid = eptList.First(ept => ept.Name == eptName).Id;
            }
            catch (Exception ex)
            {
                string msg = string.Format("GetEptUid: eptName = \"{0}\"\n\n{1}",
                    eptName, ex.GetBaseException().ToString());
                throw new ArgumentException(msg);
            }
            return eptUid;
        }

referenced from here: https://msdn.microsoft.com/en-us/library/microsoft.projectserver.client.projectcontext.waitforqueue.aspx

from this code block I have to pass in the basicEpt name, the example given being: private static string basicEpt = "SharePoint Tasks List";

I have tried multiple EPT's that I have created with varius settings, however I am still creating an Enterprise Project so either I am missing something?

There is a list of sample Projects available to download here for sharepoint: https://github.com/OfficeDev/Project-Samples

I'm interested in the "Create-Update-Project-Samples" in particular. This will give you a program which works straight away and will hopefully demonstrate what my issue is, alls that is required is to add in the function above.

Thanks for any help here, it is passing the correct GUID with the above function but it isn't saving it correctly.

enter image description here

1条回答
Evening l夕情丶
2楼-- · 2019-07-31 09:39

I also have a lot confuse about your issue, and I found that when you create a project with a tasklist, it will become sharepoint task project. Hope this will help.

var pci = new ProjectCreationInformation
            {
                Name = "new1",
                Description = "test",
                EnterpriseProjectTypeId = new Guid(""),
                //Id = Guid.NewGuid(),
                Start = DateTime.UtcNow,
                TaskList = taskList
            };
            var project = context.Projects.Add(pci);
查看更多
登录 后发表回答