Tuesday, August 9, 2011

How To Get SharePoint List form URLs Programatically

Getting the SharePoint List Item form URLs (New / Edit / View) dynamically respect to the context instead of hard-coding.

SPListItem listItem = SPList.GetItemById(itemID);

// New form full url
string newFormFullUrl = string.Format("{0}{1}?ID={2}", listItem.Web.Url, listItem.ParentList.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl, listItem.ID);

// Edit form full url
string editFormFullUrl = string.Format("{0}{1}?ID={2}", listItem.Web.Url, listItem.ParentList.Forms[PAGETYPE.PAGE_EDITFORM].ServerRelativeUrl, listItem.ID);

// Display form full url
string displayFormFullUrl = string.Format("{0}{1}?ID={2}", listItem.Web.Url, listItem.ParentList.Forms[PAGETYPE.PAGE_DISPLAYFORM].ServerRelativeUrl, listItem.ID);

//Relative Url
string newFormRelativeUrl = string.Format("{0}?ID={1}", listItem.ParentList.Forms[PAGETYPE.PAGE_NEWFORM].ServerRelativeUrl, listItem.ID);

2 comments:

  1. Please send me how can i have edit form and display form

    ReplyDelete