Accessing an SPItem via full URL Accessing an SPItem via full URL
Wishv Prajapati

Wishv Prajapati

January 28, 2013

All Post
Accessing-an-SPItem-via-full-URL
Share:

Accessing an SPItem via full encoded URL

One of the most common tasks is to access a document; heck isn’t that half of what SharePoint is about? Well in PowerShell it’s actually not obvious how to do it. I’ve used embarrassingly iterative hacks in the past, but my friend Brett Parker figured it out. Here’s the solution:

$docurl = "http ://SharePoint.com/sites/mySite/myWeb/myList/SpecificFileName.xlsx"
$site = New-Object Microsoft.SharePoint.SPSite($docurl)
$web = $site.OpenWeb()
$item = $web.GetListItem($docurl)
$list = $item.ParentList

$item now has the SPListItem, and you’re good to go.

Note that the SPDocumentLibrary is derived from the parentList property of the item.

Interestingly, the $site.openWeb() doesn’t open the RootWeb of the SPSite, but the actual web of the URL, which is great.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to talk?

Drop us a line. We are here to answer your questions 24*7.