Pages

Aug 3, 2010

How get SharePoint 2007 SpListItem DispForm Url

It's tricky to get the link to the DispForm.aspx of an SpListItem from the SharePoint 2007 object model.
In this sample you can find a piece of code to get the exact list item's url:

using (SPSite site = new SPSite("http://yoursite"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists[0];
SPListItem item = list.Items[0];
string ItemDispFormUrl = String.Concat(item.Web.Url, "/",
item.ParentList.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url, "?id=", item.ID.ToString());
}
}

No comments: