Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

2 Answers 2

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

SPForm.Type == PAGETYPE.PAGE_EDITFORM

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? –  Marius Kay Oct 19 '12 at 12:19

Your Answer

 
discard

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.