Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using the client object model and I want to access a List using the server relative Url. Folders can be accessed using the web.GetFolderByServerRelativeUrl but no such function exists for lists.

The available API is web.Lists.GetByID and web.Lists.GetByTitle which I cann't use (The list title is different from the listname/listpath)

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Try this:

public List GetListByRelativeUrl(String relativeUrl)
       List existingList;

       Web web = context.Web;
       ListCollection lists = web.Lists;

       IEnumerable<List> existingLists = context.LoadQuery(
               lists.Where( list => list.RootFolder.ServerRelativeUrl == relativeUrl)

       existingList = existingLists.FirstOrDefault();

       return existingList;

Each list has a root folder - you can find it by using the ServerRelativeUrl property.

share|improve this answer
add comment

You can use by this way:

            SP.ClientContext ctx = new SP.ClientContext("yoursiteurl");
            ctx.Credentials = CredentialCache.DefaultCredentials;
            ctx.AuthenticationMode = SP.ClientAuthenticationMode.Default;

            IEnumerable<SP.List> newLists;
            var query = from list in ctx.Web.Lists
                        where list.DefaultViewUrl == "/Shared Documents/Forms/AllItems.aspx"
                        select list;

            newLists = ctx.LoadQuery(query);
            foreach (SP.List l in newLists)
        catch (Exception ex)
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.