Friday, October 12, 2012

SPWeb.RootFolder.WelcomePage not working



You cannot set the welcome page of a non publishing site with the following code :


teamWeb.RootFolder.WelcomePage = rootFolder.Name + "/" + myPage;
teamWeb.RootFolder.Update();



Don't know the exact reason why it will not work.

But it will not work as it expected to work on.

Here is the code which you can set the welcome page of a non publishing site.

You can set this only with the SPFOlder object, Then only it will work.


SPFolder folder = context.Web.RootFolder;
folder.WelcomePage = rootFolder.Name + "/" + myPage;
folder.Update();



Thank you !!




1 comment:

  1. The reason is that every time you write teamWeb.RootFolder a new object and instance for SPFolder gets created and returned to you.

    It means you will have two different object after two teamWeb.RootFolder calls.

    The same stuff has to do with SPView property in SPList.

    Anyway, hope this help.

    Cheers.

    ReplyDelete