How To Automate The ADD IN's Deployment Using CSOM In SharePoint Online / Office 365

In this blog, I will give you the list of steps to automate SharePoint ADD IN's deployment, using CSOM.

  1. ClientContext cctx = new ClientContext(myurl);  
  2. cctx.AuthenticationMode = ClientAuthenticationMode.Default;  
  3. cctx.Credentials = new SharePointOnlineCredentials(userName, pwd);  
  4.   
  5. // Get Site Information.  
  6. Site site = cctx.Site;  
  7. Web web = cctx.Web;  
  8.   
  9. try  
  10. {  
  11. site.ActivateFeature(sideloadingFeature);  
  12. try  
  13. {  
  14. var appstream = System.IO.File.OpenRead(path);  
  15. AppInstance app = web.LoadAndInstallApp(appstream);  
  16. cctx.Load(app);  
  17. cctx.ExecuteQuery();  
  18. }  
  19. catch  
  20. {  
  21. throw;  
  22. }  
  23. //Disable SideLoadingfeatures  
  24. site.DeactivateFeature(sideloadingFeature);  
  25. }  
  26. catch (Exception ex)  
  27. {  
  28.   
  29. Console.WriteLine(string.Format(“Exception!”), ex.ToString());  
  30. Console.WriteLine(“Press any key to continue.”);  
  31. Console.Read();  
  32. }