首页 > 解决方案 > 从 Project Online 获取 ProjectSiteUrl 不起作用

问题描述

我编写了以下代码以ProjectSiteUrl从 Project Online 中发布的项目中获取属性

using (ProjectContext projContext = new ProjectContext(pwaUrl))
{
    using (SecureString securePassword = new SecureString())
    {
        Helper.GetSecurePassword(projContext, securePassword, emailID, password);

        for (int i = 0; i < listGuid.Count; i++)
        {
            #region Load Project
            string spoGuid = listGuid[i].ProjectGuid;

            if (!string.IsNullOrEmpty(spoGuid))
            {


                Guid id = Guid.Parse(spoGuid);

                var projBlk = projContext.LoadQuery(
                        projContext.Projects
                        .Where(p =>
                            p.Id == id
                        )
                        .Include(p => p.Id,
                        p => p.Tasks,
                        p => p.TaskLinks,
                        p => p.ScheduledFromStart,
                        p => p.ProjectSiteUrl,
                            p => p.Name,
                            p => p.IncludeCustomFields,
                            p => p.IncludeCustomFields.CustomFields,
                            P => P.IncludeCustomFields.CustomFields.IncludeWithDefaultProperties(
                                lu => lu.LookupTable,
                                lu => lu.LookupEntries,
                                lu => lu.LookupEntries.IncludeWithDefaultProperties(
                                    entry => entry.FullValue,
                                    entry => entry.InternalName)
                            )
                        )
                    );

                projContext.ExecuteQuery();

                poFieldValues.Add(LoadProjectsinPO(projBlk, projContext));

            }
            #endregion
            //if (i > 5)
            //{
            //    break;
            //}
            if (i % 5 == 0)
            {
                Thread.Sleep(sleepDelay);
            }
        }
    }
}

在尝试访问我得到的 ProjectSiteUrl 属性时null。我曾经得到正确的 ProjectSiteUrl,但在过去的几周里,我得到了空值。代码没有变化。

我们在 Project Online 中访问此属性的方式是否发生了变化?

标签: c#csomproject-online

解决方案


我已经修改了加载查询中加载属性的顺序,ProjectSiteUrl现在加载正常。不知道为什么它正在工作。如果有人解释这一点,将不胜感激。

 var projBlk = projContext.LoadQuery(
                        projContext.Projects
                        .Where(p =>
                            p.Id == id
                        )
                        .Include(p => p.Id,
                        p => p.ProjectSiteUrl, // Moved ProjectSiteUrl as second loading parameter.
                        p => p.Tasks,
                        p => p.TaskLinks,
                        p => p.ScheduledFromStart,

                            p => p.Name,
                            p => p.IncludeCustomFields,
                            p => p.IncludeCustomFields.CustomFields,
                            P => P.IncludeCustomFields.CustomFields.IncludeWithDefaultProperties(
                                lu => lu.LookupTable,
                                lu => lu.LookupEntries,
                                lu => lu.LookupEntries.IncludeWithDefaultProperties(
                                    entry => entry.FullValue,
                                    entry => entry.InternalName)
                            )
                        )
                    );

推荐阅读