使用 C# 为 Sharepoint 创建在线项目 [英] Creating a Project Online using C# for Sharepoint

查看:50
本文介绍了使用 C# 为 Sharepoint 创建在线项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我有一些代码可以让我在线创建 Sharepoint 项目,但是默认情况下它创建为企业项目",我想创建它作为SharePoint 任务列表""代替.(这是在线编辑项目时的以下两个选项)

我设法找到的唯一代码是改变它:

//获取指定企业项目类型的GUID.私有静态 Guid GetEptUid(string eptName){Guid eptUid = Guid.Empty;尝试{//获取具有指定名称的 EPT 列表.//如果 EPT 名称存在,则列表将仅包含一个 EPT.var eptList = projContext.LoadQuery(projContext.EnterpriseProjectTypes.Where(ept =>ept.Name == eptName));projContext.ExecuteQuery();eptUid = eptList.First().Id;//查找 EPT GUID 的替代例程.(a) 和 (b) 都下载整个 EPT 列表.//(a) 使用 foreach 块://foreach (EnterpriseProjectType ept in projSvr.EnterpriseProjectTypes)//{//if (ept.Name == eptName)//{//eptUid = ept.Id;//       休息;//}//}//(b) 查询 EPT 列表,然后使用 lambda 表达式选择 EPT://var eptList = projContext.LoadQuery(projContext.EnterpriseProjectTypes);//projContext.ExecuteQuery();//eptUid = eptList.First(ept => ept.Name == eptName).Id;}捕获(异常前){string msg = string.Format("GetEptUid: eptName = \"{0}\"\n\n{1}",eptName, ex.GetBaseException().ToString());抛出新的 ArgumentException(msg);}返回 eptUid;}

从这里引用:

解决方案

我也对你的问题有很多困惑,我发现当你创建一个带有任务列表的项目时,它会变成sharepoint任务项目.希望这会有所帮助.

var pci = new ProjectCreationInformation{名称 = "new1",描述 = "测试",EnterpriseProjectTypeId = new Guid(""),//Id = Guid.NewGuid(),开始 = DateTime.UtcNow,任务列表 = 任务列表};var project = context.Projects.Add(pci);

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)

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.

解决方案

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);

这篇关于使用 C# 为 Sharepoint 创建在线项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆