Thursday, February 5, 2009

Changing Home page Default.aspx programmatically in moss

Hi All,

Whenever we enter the URL in address bar of the browser for moss site, it automatically redirects to the Default.apsx. If we want user to go to some different page in the site.

so here is the code we write for that.

I am changing this in webpart so i am writing this code in webpart page. it is possible to have this code in Feature.

SPContext.Current.Web.AllowUnsafeUpdates = true;
SPFolder objFolder = SPContext.Current.Web.RootFolder;
objFolder.WelcomePage = "Shared%20Documents/Forms/AllItems.aspx";
objFolder.Update();
SPContext.Current.Web.AllowUnsafeUpdates = false;


Now when the user will hit the URL, it will automatically redirected to Shared Documents AllItems.aspx

That's it. you are done with this.

2 comments:

Adrienne Gross said...

thanks for the code, but where does it go? Which webpart do I paste it into?

Cheers,

Adrienne

Parth Patel said...

Hi Adrienne,

This is admin kind of stuff you can create a webpart for one time use. or you can create a feature and write this code in feature receiver.

Thanks.




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com