How get SharePoint 2007 SpListItem DispForm Url

Friday, 20 March 2009 18:14 by myro

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());
    }
}

Ops.... I almost forgot: thx peppedotnet.it !

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:   ,
Categories:   SharePoint 2007
Actions:   Bookmark and Share | Permalink | Comments (2) | Comment RSSRSS comment feed
If you consider this post usefull for your purposes, please consider visiting my sponsors to help me out with the myrocode.com maintenance. Thank you.

Comments