Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve SPList URL programmatically

Lets say I have a SharePoint List provided on URL http://webapp:1234/Lists/TestList.

In code, I have access to the corresponding SPList-Instance only. How can I get the URL of this SPList-Instance programmatically?

The SPList class is missing an URL property or something like that...

like image 452
Jonas W Avatar asked Dec 30 '11 16:12

Jonas W


2 Answers

You need to combine the list's root folder URL with the web URL. Root folder URL can be accessed via SPFolder.Url and web's absolute URL via SPWeb.Url. Providing you have a list it will be something like list.ParentWeb.Url + list.RootFolder.Url.

However, read the documentation, try it and fix things like proper slashes etc. You might also need to figure out the hostname portion of the URL from the parent SPWebApplication object. Note that the site may be accessible via multiple hostnames because of alternate access mappings.

Also, SPUtility.GetFullUrl may come in handy to convert a server-relative URL into a full URL.

like image 148
Ondrej Tucny Avatar answered Nov 05 '22 16:11

Ondrej Tucny


you can try This

SPList newlist = web.Lists(Web.Url + "Lists/listname");
like image 1
Harsh Bhavsar Avatar answered Nov 05 '22 16:11

Harsh Bhavsar