Changing form that gets displayed on list item New, Edit event

One of my colleagues (Shereen Qumsieh) has posted some excellent article on this quite common problem, which I faced in the past and pretty sure many of you had too.

As you may or may not know you can create custom forms hosted in your “_layouts” folder to perform any custom actions that can be called from anywhere within your portal. One common application is to create a custom form that will substitute default “New” or “Edit” form, so that you can handle New Item and Edit Item with your own UI and functionality.

Once you create those and host them in your _layouts folder here is how you can instruct sharepoint to call those new forms when users click New Item or Edit Item option with their default UI.

Here is how to accomplish this:
{code type=c#}
SPWeb web = SPContext.Current.Web;

web.AllowUnsafeUpdates = true;

SPList list = web.Lists["My List"];

SPContentType ct = list.ContentTypes["Item"];

ct.EditFormUrl = "_layouts/editform.aspx";
ct.NewFormUrl = "_layouts/newform.aspx";
ct.DisplayFormUrl = "_layouts/dispform.aspx";

ct.Update();
list.Update();
{/code}

This entry was posted in MOSS, sharepoint, wss and tagged , , . Bookmark the permalink.

Comments are closed.