A web part to be hosted in PWA to display projects and project related data using CSOM RRS feed

  • Question

  • Hi,

    I am currently in the process of deploying an On-Premise Project Server 2013 instance.

    Although everything out of the box is fine, we have a requirement of displaying certain pieces of information about the published projects in a summarized manner for Project Managers and Portfolio Managers/Viewers.

    For Example, when a user (Proj Mgr, or Portfolio Mgr) logs in they are able to see a list of projects as per their user level in the Project Center web part. In addition to the Project Center, We need to show the following information based on the projects that the user can access:

    A tabular view displaying values of various custom enterprise fields associated to each of project (e.g. expected completion date, expected start date, actual start date, actual completion date etc.)

    In order to achieve this, we are trying to use the Project Server 2013 CSOM in a web part to retrieve the project related information, however, we are unable to even get the ProjectContext initialized. Following is the code from the Visual Web Part solution created using Visual Studio 2013: (I would appreciate help using the c# CSOM as I don't want to use the Javascript Object model JSOM)

    protected void Page_Load(object sender, EventArgs e) { this.lblOutput.Text = "No Data, No Value"; try { string pwaPath = "http://ps2013instance/pwa"; projContext = new ProjectContext(pwaPath); projContext.Credentials = CredentialCache.DefaultNetworkCredentials;

    // Get the list of published projects in Project Web App. projContext.Load(projContext.Projects); projContext.ExecuteQuery(); StringBuilder sb = new StringBuilder(); //Prepare output string using the project listing foreach (PublishedProject pubProj in projSvr.Projects) { sb.Append("<br>" + pubProj.Id.ToString() + " : " + pubProj.Name + " : " + pubProj.CreatedDate.ToString()); } lblOutput.Text = sb.ToString(); } catch (Exception ex) { lblOutput.Text = ex.Message + ex.StackTrace; } }

    The output of the web part code above is as follows:

    Access denied. You do not have permission to perform this action or access this resource. at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at WPProjectList_CS.VisualWebPart1.VisualWebPart1UserControl.Page_Load(Object sender, EventArgs e)

    I would really like some help in this regard. I have spent weeks researching on Google however, there is no clarity on how to use the CSOM withing a web part hosted on the PWA. The examples are all given for using C# CSOM from console applications and none of them are for webparts hosted within PWA

    (I would appreciate help using the c# CSOM as I don't want to use the Javascript Object model JSOM)



    • Edited by Ritzzz Wednesday, October 29, 2014 10:53 AM
    Wednesday, October 29, 2014 10:46 AM

All replies

  • Hello,

    Assuming the additional data you want to see is all Project level customs fields, why can't you just create / modify a project center view in PWA to show this information? This would then all be out of the box, this can be done on the PWA Settings > Mange Views page. Paul

    Paul Mather | Twitter | | CPS

    Sunday, November 2, 2014 5:32 PM
  • Hi Paul,

    First of all - my apologies for the late response.

    Thanks for the insight. In fact I was already able to create a custom view for the Project Center.

    However, there are a few other sets of data that we need to retrieve from the project sites (e.g. delayed tasks, upcoming tasks etc, and also a lists of project documents uploaded to the Doc Libs of various project sites based on a specific DocType field assigned to each document.). This is the reason we need to iterate through each published project, get site URL and then retrieve the required data.

    Please let me know if this is achievable using the c# CSOM. Because for some reason the c# code does not seem to run inside a webpart at all and gives the same error as in my original query.



    Monday, January 5, 2015 2:43 PM
  • Hi ritzzz. It could easily be you do not actually have the permissions to read the projects. Try wrapping in RunWithElevatedPrivileges like this:

                        // create project context
                        logString = "About to get project context";
                        projContext = new ProjectContext(pwaPath);
                        // load projects
                        logString = "About to get projects";
                        // load custom fields
                        logString = "About to get custom fields";

    Monday, January 12, 2015 6:19 PM