4

I've an application where i show the bunch of lists in a site. I can click add new item right there and i want to redirect the user to the 'add new item URL' for the particular list he has selected. But the URLs are not uniform.

For ex -

For Tasks the add new item URL is http://webapp1/Lists/Tasks/NewForm.aspx. For WorkFlow Tasks it is http://webapp1/WorkFlowTasks/NewForm.aspx

How can i get/built these URLs through code?

NLV
  • 490
  • 5
  • 21

1 Answers1

5

From MSDN article about SPForm class:

Use the Forms property of the SPList class to return an SPFormCollection object that represents the collection of forms for a list, and use an indexer to return a single form from the collection.

Sample:

SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["Contacts"];
SPFormCollection collForms = oList.Forms;
foreach (SPForm oForm in collForms)
{
    Response.Write(oForm.Url + " :: " + oForm.Type + "<BR>");
}

WorkFlow Tasks is usually system library (for workflow tasks) and you really should not allow people to add tasks in this one.

Use SPList BaseTemplate property to differentiate list types.

Toni Frankola
  • 4,319
  • 28
  • 38
  • How can i substantially differentiate and identify System Libraries from other libraries? – NLV Aug 02 '10 at 11:16
  • Check BaseTemplate property: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.basetemplate(office.12).aspx – Toni Frankola Aug 02 '10 at 11:25