How to Get SharePoint Library from Document Path

Rog D
Rog D used Ask the Experts™
on
Using C# and CSOM I would like to get the SharePoint library a document belongs to using the Path or Hyperlink of that file.

I am sure this is possible, but could not find anything that showed an example.

Exmple Of Path:  http://uatecm.MyTestSite.com/repository/current/Test/MUSTREAD,%20FLOYD.pdf

I am using Microsoft.SharePoint.Client via a web application.

Thanks,

Roger
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
RobertSystem Admin

Commented:
In your example I believe "repository" would be the name of the document library.

That said the best way to find it is to go into your site contents (if you have rights to do so)
Rog DSQL Developer / Web Development / Business Analysis

Author

Commented:
I am looking for some code example that would allow me to pass in the full URL of the file then allow me know the Library where this file belongs to.

 http://uatecm.test.com/repository/current/Testing/MUSTREAD,%20FLOYD.pdf

Thanks,

Roger
System Admin
Commented:
The following assumes the format of the URL will stay same
If you want to pass it a single url and have it tell you what library you could use something like this powershell script.
you can modify it to output any way you want but should get you started.

$URL = Read-Host -Prompt 'Input your URL'
$split = $url -split '/'
$Library = $split[3] 
$file = $split[6]
$output = $file +' is in library ' + $Library
Write-Output $output

Open in new window


if you have a list of the url's i.e. URL.txt
you would just add the code to get the content. and loop through.

$logfile = 'c:\temp\log.txt'
Function Log ($strMsg)
{

     $LogEntry = $strMsg
     add-content $LogFile $LogEntry
}

foreach ($line in Get-Content 'c:\temp\url.txt')
{

$split = $line -split '/'
$Library = $split[3] 
$file = $split[6]
$strmsg = $file +' is in library ' + $Library
Log $strmsg
}

Open in new window

Rog DSQL Developer / Web Development / Business Analysis

Author

Commented:
I will use this solution for now as I expect the current path to always have the Library name in the same spot.

Thanks for the examples as well.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial