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?

3
  • Okie i guess it is going to take a long time for me to get an answer here.
    – NLV
    Aug 2, 2010 at 6:37
  • Long time, like 2 hours and 9 minutes?
    – Ryan
    Jun 8, 2011 at 11:23
  • Sorry for my bad comment. Apologies.
    – NLV
    Jun 8, 2011 at 13:36

1 Answer 1

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.

2

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.