ProjectServerCredentials

ProjectServerCredentials class

Credentials which are used to connect to Project Online or on-premise instance of Project Server.

public sealed class ProjectServerCredentials

Constructors

Name Description
ProjectServerCredentials(string, NetworkCredential) Initializes a new instance of the ProjectServerCredentials class using URL of Project Web Access endpoint and network credentials.
ProjectServerCredentials(string, string) Initializes a new instance of the ProjectServerCredentials class using URL of SharePoint site and valid SPOIDCRL authorization token for SharePoint’s PWA (Project Web Access) site.
ProjectServerCredentials(string, string, string) Initializes a new instance of the ProjectServerCredentials class using URL of SharePoint site, user name and password.

Properties

Name Description
AuthToken { get; } Gets the authorization token for the SharePoint instance.
SiteUrl { get; } Gets the URL of PWA at SharePoint site or URL of on-premise Project Server. For example, https://your_company_name.sharepoint.com/sites/pwa";
UserName { get; } Gets the user name for SharePoint site.

Methods

Name Description
override ToString() Returns a string representation of this instance.

Examples

Shows how to use project server credentials to retrieve list of project from Microsoft Project Online.

try
{
    const string SharepointDomainAddress = "https://contoso.sharepoint.com/sites/pwa";
    const string UserName = "admin@contoso.onmicrosoft.com";
    const string Password = "MyPassword";

    var credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);

    var newProject = new Project(DataDir + @"Project1.mpp");

    var manager = new ProjectServerManager(credentials);
    manager.CreateNewProject(newProject);

    IEnumerable<ProjectInfo> list = manager.GetProjectList();

    foreach (var info in list)
    {
        var project = manager.GetProject(info.Id);
        Console.WriteLine("{0} - {1} - {2}", info.Name, info.CreatedDate, info.LastSavedDate);
        Console.WriteLine("Resources count: {0}", project.Resources.Count);
    }
}
catch (ProjectOnlineException ex)
{
    Console.WriteLine(ex.Message);
}

See Also