Oddly enough, the SPList object doesn’t have a URL property which gives you the server relative URL of the List.
So, here’s a code snippet to retrieve it.
private static string GetListURL(SPList theList, bool serverRelative) { var listUrl = theList.DefaultViewUrl; if (theList is SPDocumentLibrary) { var idx = listUrl.IndexOf("Forms"); listUrl = listUrl.Remove(idx); if (listUrl.EndsWith("/")) listUrl = listUrl.Remove(listUrl.LastIndexOf("/")); } else { var idx = listUrl.LastIndexOf("/"); listUrl = listUrl.Remove(idx); } if (!serverRelative) { var serverUrl = theList.ParentWeb.Url; serverUrl = serverUrl.Substring(0, serverUrl.IndexOf("/", 7)); listUrl = serverUrl + listUrl; } return listUrl; }
theList.RootFolder.Url!