Wednesday, July 18, 2012

setting custom list forms to content type

Share/Save/Bookmark


Setting custom display/edit list forms to a content type

What i was aksed to do is if i can create custom form pages that can be set to the items of specific content type. Though i'm not sure of the second part im started with first part,creating the custom form for displayform.aspx.
So, I copied the existing form and added my custom control to it.
I tred to place the new form(customdisplayform.aspx) in the same location(listname\forms\) where OOB forms exist for a library/iist through a feature.
Though feature deploys the form to the location, i see the listformwebpart missing when i open the form in sharepoint designer.
Also, i have to set the propertiesand ListName and ListId of listformwebpart dynamically, so i decided to go for a application page with code behind in which the properties are set onInit as below.

listFormWP.ListName = SPContext.Current.Web.Lists["lib"].ID.ToString();

listFormWP.ListId = SPContext.Current.Web.Lists["lib"].ID;
Now, application page will have the same markup as is just that it will inherit layoutspagebase class.
so now we have the form ready but how to associate with the library or list? here is the code,

SPList list = web.Lists["lib"];
list.DefaultEditFormUrl = "/../_layouts/mlp/CustomEditForm.aspx";

list.DefaultDisplayFormUrl = "/../_layouts/mlp/CustomDisplayForm.aspx";

list.update();

Custom list forms can also be associated to content type as below,

SPContentType reportCT = list.ContentTypes[contentType];


reportCT.DisplayFormUrl = "/../_layouts/mlp/CustomDisplayForm.aspx";

reportCT.EditFormUrl = "/../_layouts/mlp/CustomEditForm.aspx";

reportCT.Update();

Please let me know if anybody found something on the missing markup issue when custom list form is provisioned inside the path of the library rather under layouts.

 Subscribe

No comments:

Post a Comment