Get and Update Welcome Page URL

I have created a console application, which fetches and updates the welcome page url to the site using CSOM. For that, we have to add the Managed Client Object SharePoint dlls as reference to the project.
 
Microsoft.SharePoint.Client.dll
 
Microsoft.SharePoint.Client.Runtime.dll
 
After the references are added, insert the following snippet to the development area,
  1. static void Main(string[] args)  
  2.         {              
  3.             ClientContext ctx = new ClientContext("https://sharepointsite");  
  4.             ctx.Credentials = new System.Net.NetworkCredential("<User Name with Domain>"" <Password >");  
  5.             Web web = ctx.Web;  
  6.   
  7.             //Fetch the Welcome Page URL from the given Web  
  8.             GetHomePage(web);  
  9.               
  10.             //Update the Welcome Page URL to the given Web  
  11.             string welcomePageURL = "sitepage/home.aspx";  
  12.             UpdateHomePage(web, welcomePageURL);              
  13.         }  
  14.   
  15.         /// <summary>  
  16.         /// Update the welcome page to the website  
  17.         /// </summary>  
  18.         /// <param name="web">SharePoint COM Web Object</param>  
  19.         /// <param name="welcomePageURL"> Relative URL</param>  
  20.         private static void UpdateHomePage(Web web, string welcomePageURL)  
  21.         {  
  22.             ClientRuntimeContext ctx = web.Context;  
  23.             var rootFolder = web.RootFolder;  
  24.             rootFolder.WelcomePage = welcomePageURL;  
  25.             rootFolder.Update();  
  26.             ctx.ExecuteQuery();  
  27.             Console.WriteLine("Welcome Page updated successfully.");  
  28.             Console.Read();  
  29.         }  
  30.   
  31.         /// <summary>  
  32.         /// Get the welcome page for the websote  
  33.         /// </summary>  
  34.         /// <param name="web">SharePoint COM Web Object</param>  
  35.         private static void GetHomePage(Web web)  
  36.         {  
  37.             ClientRuntimeContext ctx = web.Context;  
  38.             Folder folder = web.RootFolder;              
  39.             ctx.Load(folder);  
  40.             ctx.ExecuteQuery();  
  41.             Console.WriteLine("Welcome Page Relative URL: " + folder.WelcomePage.ToString());  
  42.             Console.Read();  
  43.         }  
 Hope, you have enjoyed the snipper