Making ServerRelativeUrl work on SPListItems

ServerRelativeUrl only work on the SPFile class so you can´t use SPListItem to get access to that property, example:


But, the SPListItem has a column named FileRef that holds that information so by making an extension method you can get around that:

public static string ServerRelativeUrl(this SPListItem item)
    return item[SPBuiltInFieldId.FileRef].ToString();
And, now it works!

  1. Leave a comment

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: