SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does the SharePoint Client Object Model have any method to access an object (List, Document, etc.) with just a single URL and valid credentials?

Essentially, I want to access an object ( programmatically like this:

var credentials = new System.Net.NetworkCredential("user", "pass", "domain");
using (var sp = new ClientContext("") { Credentials = credentials })
    var file = sp.Web.GetFileByServerRelativeUrl("/Lib1/Sample.pdf");

I want to do this, except without knowing ahead of time which part of the URL corresponds to the site and which part points me to the object. So, I'm wondering if I have to make my own logic for this or if the Client Object Model has something for me to accomplish this.

share|improve this question
up vote 2 down vote accepted

There is no "get by URL" method for lists in the client object model that I am aware of.

About the closest thing you have is a GetFolderByServerRelativeUrl on the Web object:


Depending on what you want to do this might work for you...unfortunately you can't get the parent list from the folder object like you can in the .NET api.

Source - Similar question

Since you can't get a list by URL so I would assume you can't get a document by url either, but you can try doing it this way tho,

var fileItem = Web.GetFileByServerRelativeUrl("server/relative/url");

context.Load(fileItem); //you will probably need to load the ListItemAllFields property here.

var listItem = fileItem.ListItemAllFields; 


Source - getlistitemstrurl-equivalent-for-clientcontext

Hope it helps :)

share|improve this answer

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.