using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Web.Services.Protocols; using PSLibrary = Microsoft.Office.Project.Server.Library; namespace GetProjectList { class Program { const string PROJECT_SERVICE_PATH = "_vti_bin/psi/project.asmx"; const int PROJECT_ENTITY_TYPE_PROJECT = 1; static void Main(string[] args) { string PROJECT_SERVER_URI = "http://ServerName/ProjectServerName/"; if (args.Length == 1) { PROJECT_SERVER_URI = args[0]; try { ProjectWS.Project projectSvc = new ProjectWS.Project(); projectSvc.Url = SetProjectURL(PROJECT_SERVER_URI); projectSvc.Credentials = CredentialCache.DefaultCredentials; // read all the projects Console.WriteLine("Read the project list for this user"); ProjectWS.ProjectDataSet readProjDs = projectSvc.ReadProjectStatus(Guid.Empty, ProjectWS.DataStoreEnum.PublishedStore, string.Empty, (int)PSLibrary.Project.ProjectType.Project); ProjectWS.ProjectDataSet currentProjectDS; ProjectWS.ProjectDataSet.ProjectRow curProj; foreach (ProjectWS.ProjectDataSet.ProjectRow project in readProjDs.Project) { // Get the full dataset with the ReadProject call //currentProjectDS = projectSvc.ReadProject(project.PROJ_UID, GetProjectList.ProjectWS.DataStoreEnum.PublishedStore); // or get just the pieces of the dataset you want with the ReadProjectEntities call currentProjectDS = projectSvc.ReadProjectEntities(project.PROJ_UID, PROJECT_ENTITY_TYPE_PROJECT, ProjectWS.DataStoreEnum.PublishedStore); curProj = currentProjectDS.Project[0]; Console.WriteLine(String.Format("{0} Starts {1}, Completes {2}", curProj.PROJ_NAME, curProj.PROJ_INFO_START_DATE.ToLongDateString(), curProj.PROJ_INFO_FINISH_DATE.ToLongDateString())); } } catch (SoapException ex) { PSLibrary.PSClientError error = new PSLibrary.PSClientError(ex); PSLibrary.PSErrorInfo[] errors = error.GetAllErrors(); string errMess = "==============================\r\nError: \r\n"; for (int i = 0; i < errors.Length; i++) { errMess += "\n" + ex.Message.ToString() + "\r\n"; errMess += "".PadRight(30, '=') + "\r\nPSCLientError Output:\r\n \r\n"; errMess += errors[i].ErrId.ToString() + "\n"; for (int j = 0; j < errors[i].ErrorAttributes.Length; j++) { errMess += "\r\n\t" + errors[i].ErrorAttributeNames()[j] + ": " + errors[i].ErrorAttributes[j]; } errMess += "\r\n".PadRight(30, '='); } Console.WriteLine(errMess); } catch (WebException ex) { string errMess = ex.Message.ToString() + "\n\nLog on, or check the Project Server Queuing Service"; Console.WriteLine("Error: " + errMess); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } finally { Console.WriteLine("\r\n\r\nPress any key..."); Console.ReadKey(); } } else { Console.WriteLine("USAGE: GetProjectList ProjectServerInstance"); Console.WriteLine(" ProjectServerInstance Required parameter in the form of http://servername/pwainstance"); Console.WriteLine("\r\n\r\nPress any key..."); Console.ReadKey(); } } private static string SetProjectURL(string PSInstance) { if (!PSInstance.EndsWith("/")) PSInstance += "/"; return PSInstance + PROJECT_SERVICE_PATH; } } }