SharePoint SharePoint Server client object model retrieves list item from URL

Is there a way to get a List object using Url?

I know that you can get the list by name:

ClientContext context = new ClientContext("http://foo");

List list = context.Web.Lists.GetByTitle("title");

context.Load(list);
context.ExecuteQuery();

But I want the user to be able to copy-paste the URL from his browser into the text box (e.g. http: //foo/subsite/ListName/Forms/AllItems.aspx ) and then extract the List object from this url.

+5
source share
2 answers

No, there is no method to get the object Listdirectly from the URL. As you indicated, you can get it from the list header, and you can also get it through your identifier (see ListCollection.GetById).

- URL; URL- SharePoint . / URL- , URL- , - /Forms/[ViewName].aspx. "/Forms/" , , .

, , ArgumentException, , , .

+5

:

private static List GetListByServerRelativeUrl(string serverRelativeUrl)
{
    using (ClientContext ctx = new ClientContext("http://yoursite"))
    {
        var q = from list in ctx.Web.Lists
                where list.RootFolder.ServerRelativeUrl == serverRelativeUrl
                select list;
        var r = ctx.LoadQuery(q);
        ctx.ExecuteQuery();
        return r;
    }
}
0

All Articles