I've started creating all my SP lists in-code, because I find it to be way more reliable than using schemas. I can ensure lists on-the-fly, change existing fields during development, etc. And if someone breaks my list by deleting a field or something, I can just re-ensure the list with my code, and everything is fixed.

But what I haven't been able to figure out how to do yet is set up customized form templates. For example, in a schema, you'd normally do something like this:

  <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" Template="ListTemplateName" />
  <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" Template="ListTemplateName" />
  <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" Template="ListTemplateName" />

I want to do that same thing, except I want to do it on a list that already exists (we're working on version two of a web app). I want customized forms for the New and Edit forms for a list.

I can't seem to be able to edit anything spList.Forms. Everything is a getter, not a setter. How do I define my own list in code, as I would have done in a schema with the example above?


Found an answer to your question in this blog. Author of this blog says what you are asking is possible. In his words

You have created a custom list through the browser and now you just need to change the forms displayed by default or you just want to do that programmatically without editing the list content type definition!?! That’s possible, just keep reading!


| improve this answer | |
  • 1
    I'm marking this correct with some extra info ... I wanted to use a template, not a custom aspx page. YOu do this with: SPContentType ct = list.ContentTypes["Item"]; ct.NewFormTemplateName = "CustomTemplateNameWhichYouPutInControlTemplates"; ct.Update(); – Craig Oct 8 '13 at 16:05

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.