I want to delete the Site page which is set as home page. Now I have created a feature and on deactivating it the Site page is deleted. But I am facing the error as follows :

The item that you are trying to delete is the current welcome page and cannot be deleted.

As this is a home page so it doesn't allowing me to delete it. But I want to delete it.

Is there any way to delete forcefully (Programmatically)

Any help would e appreciated

  • Add a new page, set it as welcome page. Then delete the old page – Robert Lindgren Mar 16 '17 at 9:41

The error is pretty much self explanatory. You need to set a different page as welcome page first and then delete your current welcome page.

Try and modify below code as per you requirement:

using (SPSite oSiteCollection = new SPSite("https://sitecollectionurl"))
    //change as per your spweb 
    SPWeb rootWeb = oSiteCollection.RootWeb;
    SPFolder rootFolder = rootWeb.RootFolder; 
    //change welcome page to a different page, ensure path is correct
    rootFolder.WelcomePage = "default.aspx"; 

    SPFile oldHomePage = rootWeb.GetFile("url of page to be deleted");
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.