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

Let's say the only input I have from the user is the full URL to a folder in a Document Library called "Public Documents":

http://intranet.contoso.com/SubSite/PublicDocuments/Folder/SubFolder/

Using the ClientContext constructor from the client object model, I can't pass it the full URL because it will say site not found under "SubFolder". I have to somehow parse the URL to pass either the site collection or the web "SubSite" to the ClientContext constructor to get a ClientContext.

What are some creative ways to parse the URL to get the CSOM objects from the URL string:

  • Site
  • Web
  • List
  • Folder

Thanks for your help!

share|improve this question

1 Answer 1

I'd generally start at the site collection level.

After the FQDN level there are a couple of options: a document library, a subsite or a managed path. If you can create a SPWeb from SubSite then you are good. From there you can look for a document library called PublicDocuments (lists tend to have /lists/ in the URL) and then find folders as described by the rest if the URL.

If you are unable to get an SPWeb from the SubSite part of the URL then you can try to get a document library object otherwise you know it's a a managed path and you can connect to the site site collection given by the URL up to the part after the managed path.

That's how I'd start.

Mark

share|improve this answer

Your Answer

 
discard

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.