DispForm extension method

A while back I write  post about getting the EditForm url of a SPListItem.

This is another one of those nice to have extension methods for the SPListItem class. This one gets you the url of the DisplayForm (DispForm.aspx).
Here is the code for that extension method:


public static string DisplayFormUrl(this SPListItem item)
{
    const string format = "{0}?id={1}";

    return string.Format(CultureInfo.InvariantCulture, format,
        item.ParentList.Forms[PAGETYPE.PAGE_DISPLAYFORM].ServerRelativeUrl,
        item.ID.ToString());
}

and now you can write code like this:


SPListItem item = // get item code goes here;
return item.DisplayFormUrl();

 

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: