If we want to connect to microsoft project online in a web or desktop application we have written, we must have a microsoft account that can enter this tenant. With this microsoft account we will connect to project online with our application.

Project Online Bağlantısı

If we want to connect to microsoft project online in a web or desktop application we have written, we must have a microsoft account that can enter this tenant. With this microsoft account, we will connect to project online with our application

However, there is an important point here. If the account you will login to has multi factor authentication, the process changes. If you don't want to make it difficult at this stage, you can make the process easier by turning off the multi factor of this user. If you want to log in without turning off multi factor, I can prepare a different content about it.

Related libraries;

using Microsoft.SharePoint.Client;
using Microsoft.ProjectServer.Client;

Connection codes;

  string siteUrl = "https://{tenant}.sharepoint.com/sites/pwa";
  string username = "mryed@{tenant}.com";
  string password = "hesapsifresi";

              //Proje bağlantısı oluşturma
              using (ProjectContext context = new ProjectContext(siteUrl))
              {
                  SecureString securePassword = new SecureString();
                  foreach (char c in password.ToCharArray())
                  {
                      securePassword.AppendChar(c);
                  }
                context.Credentials = new SharePointOnlineCredentials(username, securePassword);
                var allprojects = context.Projects;
                context.Load(allprojects);
                context.ExecuteQuery();

                //Proje sayısını, adını ve guid id bilgilerini çekiyoruz.
                Console.WriteLine("Projects:" + allprojects.Count);
                Console.WriteLine("-----------");
                foreach (PublishedProject project in allprojects)
                {
                    Console.WriteLine("Proje Adi: " + project.Name);
                    Console.WriteLine("Proje GUID: " + project.Id);
                    Console.WriteLine("-----------");
                }
                try
                {
                      Guid projectId = new Guid("{Proje GUID}");
                      PublishedProject project = context.Projects.GetByGuid(projectId);
                      context.Load(project);
                      context.Load(project, p => p.StartDate, p => p.Description, p => p.CustomFields, p=>p.Owner);
                      context.ExecuteQuery();
                      Console.WriteLine("Projenin Başlangıç Tarihi: " + project.StartDate);
                      Console.WriteLine("Proje Açıklaması: " + project.Description);
                      Console.WriteLine("Proje Sahibi: " + project.Owner);

                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine("Hata: " + ex.Message);
                  }
              }

Project Online Data Extraction

Let me briefly explain the codes at this stage. First of all, we get our user information in string variables. Then we prepare a context with this information. Now we will do our operations with this context. In the rest of the code, we pull all the projects and print how many projects we have, project names and guid numbers. This guid number is important for us. Because later we will connect to the project with these numbers.

I added a try-catch blog to connect to the project. In this blog, I connect to the project by typing the guid number of the project. At this stage, I pull information such as the owner of the project and the start date.

There are tasks in these projects. In another article, I will talk about how to pull data from these tasks and how to update data.

See you in the next article content...