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,
- static void Main(string[] args)
- {
- ClientContext ctx = new ClientContext("https://sharepointsite");
- ctx.Credentials = new System.Net.NetworkCredential("<User Name with Domain>", " <Password >");
- Web web = ctx.Web;
-
-
- GetHomePage(web);
-
-
- string welcomePageURL = "sitepage/home.aspx";
- UpdateHomePage(web, welcomePageURL);
- }
-
-
-
-
-
-
- private static void UpdateHomePage(Web web, string welcomePageURL)
- {
- ClientRuntimeContext ctx = web.Context;
- var rootFolder = web.RootFolder;
- rootFolder.WelcomePage = welcomePageURL;
- rootFolder.Update();
- ctx.ExecuteQuery();
- Console.WriteLine("Welcome Page updated successfully.");
- Console.Read();
- }
-
-
-
-
-
- private static void GetHomePage(Web web)
- {
- ClientRuntimeContext ctx = web.Context;
- Folder folder = web.RootFolder;
- ctx.Load(folder);
- ctx.ExecuteQuery();
- Console.WriteLine("Welcome Page Relative URL: " + folder.WelcomePage.ToString());
- Console.Read();
- }
Hope, you have enjoyed the snipper