SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a new edit form for my SPList via Sharepoint Designer and haven't deleted the old ones. I know how to get all the forms, but how to distinguish default forms from the rest?

I can see in Sharepoint Designer which one is set to default, but can I get this information programatically?

My current function gets all the forms and distuingishes only by PAGETYPE. What can I improve?

public static string getFormName(string listName, PAGETYPE formType)
   SPFormCollection forms = SPContext.Current.Web.Lists[listName].Forms;
   foreach (SPForm form in forms)
      // todo: how to choose default form
   return formName;
share|improve this question
up vote 1 down vote accepted

While working on something else I accidently found an answer to this one. When I have an SPList in code, like this:

SPList myList = SPContext.Current.Web.Lists[listName];

I can get default forms from SPList properties:

string defaultEditForm    = myList.DefaultEditFormUrl;
string defaultDisplayForm = myList.DefaultDisplayFormUrl;
string defaultNewForm     = myList.DefaultNewFormUrl;

I hope this will come in handy for someone in the future :-)

share|improve this answer


share|improve this answer
While this post may answer the question, we prefer more details such as "why". Please edit your post with additional details. See answer for general guidelines. – SPDoctor Oct 17 '12 at 13:59
Doesn't solve my problem. Already tried that. Let's say I have two edit forms assigned to one list. If I used your condition to get the number of all edit forms, then I would get two. Because both of them will return true for (SPForm.Type == PAGETYPE.PAGE_EDITFORM). But how to tell which one is set to default? – Maurice Kay Oct 19 '12 at 12:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.