how can i know the wiki pages that are referencing a document inside my enterprise wiki site collection
-
03-10-2020 - |
Вопрос
I am working on an enterprise wiki site collection and I have two libraries; “Page” which contain the html wiki pages & “Documents” which contain uploaded documents. Now on some wiki pages users upload documents inside the “Documents” library (such as word document or pdfs), and then they reference them inside the wiki pages.
So my question is that we need to identify all the wiki pages that have links to documents , so is this possible?. Now for a wiki pages if I want to know all the wiki pages that are referencing it, I can check the “incoming links” option under “Page Option” tab,, so is there a similar option for the documents? i mean to check which wiki pages are referencing it ?
Thanks
Решение
The SPFile
object has a ForwardLinks
and BackwardsLink
property that contain SPLinkCollection
that you may be able to query.
Add-PSSnapin Microsoft.SharePoint.Powershell -ea 0;
$web = get-spweb '<url>'
$list = $web.lists['Pages'];
foreach($file in $list.items){
$links = $file.ForwardLinks;
foreach($link in $links){
if($link.url -like '*/Documents/*'){
Write-Host $file.name $link.url
}
}
}
You can also use CSOM - which doesn't appear to expose the ForwardLinks
/BackwardLinks
properties, but I was able to get at the HTML content of the page and could search across that as a string.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$weburl = 'https://<URL>';
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
$ctx.Credentials = Get-Credential;
$web = $ctx.Web;
$ctx.Load($web);
$list = $web.Lists.GetByTitle('Pages');
$ctx.load($list);
#Note - you can create a specific CAML query to get specific documents as well.
$query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(10);
$items = $list.GetItems($query);
$ctx.Load($items);
$ctx.ExecuteQuery();
foreach($fileItem in $items){
$pageContent = $fileItem['PublishingPageContent'];
If($pageContent | select-string -Pattern '/documents/' -SimpleMatch){
#page has link to documents library
Write-Host "Page has link"
}
}