Delete Project Programmatically Project Online using CSOM

Delete Project Programmatically Project Online using CSOM

Delete Project Programmatically Project Online using CSOM.In project server, there is a feature to delete the project manually. In the section Queue and Database Administration and click on Delete Enterprise Objects. .But when we need to delete the project in bulk then we need to write some code. Below is code for Delete Project Programmatically Project Online using CSOM.

If you don’t know to add references in your solutions then follow the post below

Add  references in Solution

var projCollection = clientContext.LoadQuery(

If you want to delete all project, use above query.

JobState jobState5 = clientContext.WaitForQueue(DraftProj.CheckIn(true), 20);

First check-In all project.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.ServiceModel;
using System.Data;
using Microsoft.ProjectServer.Client;
using Microsoft.SharePoint.Client;
using System.Security;

namespace Update_Custom_Field_Using_CSOM
    class Program
        static string UserName = "UserName";
        static string Passwords = "Password";
        public static string OnlinePWA = "PWAPath";
        static void Main(string[] args)
            DeleteProjectCSOM("Project Name");

        private bool DeleteProjectCSOM(string projectName)
            using (ClientContext clientContext = new ClientContext(pwaPath))
                SecureString passWord2 = new SecureString();
                foreach (char c in Passwords.ToCharArray()) passWord2.AppendChar(c);
                clientContext.Credentials = new SharePointOnlineCredentials(UserName, passWord2);

                var projCollection = clientContext.LoadQuery(
                        .Where(p => p.Name == projectName));
                int numProjectsInCollection = projCollection.Count();
                if (numProjectsInCollection > 0)
                    PublishedProject pubProj = projCollection.First();
                    DraftProject DraftProj = pubProj.Draft;
                    JobState jobState5 = clientContext.WaitForQueue(DraftProj.CheckIn(true), 20);
                    JobState jobState = clientContext.WaitForQueue(context.Projects.Update(), 20);
                    JobStateLog(jobState, "Project Deleted");





Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!