Skip to primary content
Skip to secondary content

SharePointed

SharePoint and Power Platform and Stuff

SharePointed

Main menu

  • About | Contact
  • Privacy Policy

Tag Archives: metadata

SharePoint Online and Copied Metadata

Posted on March 9, 2021 by Ian Hayse
6

Out of the box, if you upload a document to SharePoint and tag metadata to it, that data is attached to the document properties. This is the case for most all column types you create in a library, and on random occasions, Document IDs are copied.

If you are working with SharePoint on-prem you can disable this functionality at the SPWeb level, but that’s not the case with SharePoint Online.

on-prem code example:
$web = $ctx.Web
$web.ParserEnabled=$false
$web.Update()


Example of what I was seeing in my sample library:
Create a new library titled DocLib
Added a text column titled TacoFiller
Uploaded an Excel file, then populate TacoFiller with the word Beans


Downloaded the file and look at the properties.
File –> Info –> All Properties (Excel o365)

Notice that property TacoFiller is set to Beans.

Create a local copy of the file, then upload it to DocLib.



SharePoint has read the TacoFiller property from the Excel file and applied the data to the column in the library.

Short of doing a document migration, I have NO idea why you’d want this enabled out of the box. If anything, this should be disabled, then allow admins to enable as needed. /rant

TL;DR / how-to disable this functionality:
First, you can only disable this at the library level!

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Code\DLL\Microsoft.SharePoint.Client.dll"    
Add-Type -Path "C:\Code\DLL\Microsoft.SharePoint.Client.Runtime.dll"    
     
#Config Parameters
$SiteURL= "https://YourSite.sharepoint.com/sites/spdev/testsite"
$ListName="DocLib"
   
#Get Credentials to connect
$Cred = Get-Credential
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
     
    #get list sharepoint online powershell
    $List=$Ctx.Web.Lists.GetByTitle($ListName)
    $Ctx.Load($List)
    $Ctx.ExecuteQuery()    
 
    Write-host "Parser Disabled value " $List.ParserDisabled

    $List.ParserDisabled = $true
    $List.Update()
    $ctx.ExecuteQuery()

}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

A couple of notes about the script.
You can download the SharePoint DLLs from Microsoft: link
In my tenant, using Get-Credential requires that I use my company email address and an App Password. This may/not be the case with your tenant. App Password info: link

And… after running the script, upload another copy of the Excel file to the library.


The TacoFiller property is no longer being extracted from the Excel file!

I’d like to thank Abhijit Rajurkar for helping with this!

Posted in CSOM, SharePoint, SPO | Tagged Document ID, metadata, ParserDisabled, sharepoint online | 6 Replies

Copy files to another document library maintain metadata

Posted on June 17, 2011 by Ian Hayse
13

(this applies to MOSS / WSS 2007) Scroll to the bottom for a script that will work with SharePoint 2010.

How do you move all the fires from library A to library B?
Easy answer is to open both libraries in Explorer View and copy them over.
Doing this is quick and easy, but your metadata will be lost (if you care).

In my case I had to maintain the metadata when moving a bunch of files to a library in another site.

[System.Reflection.Assembly]::LoadWithPartialName(”Microsoft.SharePoint”)

$siteUrl = "http://sharepoint"
$webName = ""

$spSite = new-object Microsoft.SharePoint.SPSite($siteurl)

$spWeb = $spSite.OpenWeb($webName)

$spList = $spWeb.Lists["Documents"]

$listItems = $spList.Items
$listTotal = $listItems.Count

for ($x=$listTotal-1;$x -ge 0; $x--)
{
try
{  $listItems[$x].CopyTo("http://sharepoint/Docs/Documents/"+ $listItems[$x].name)
  Write-Host("DELETED: " + $listItems[$x].name)
  $listItems[$x].Recycle()
  }
Catch
{
Write-Host $_.Exception.ToString()
}
}

$spSite.Dispose
$spWeb.Dispose

$listItems[$x].Recycle() can be replaced with $listItems[$x].Delete()
I wanted to move the items to the Recycle Bin for safe keeping.

If the file already exists in the destination library, the file will not be moved or deleted.
*if you wanted to deal with this scenario, you could simply create a new file name in the Catch event, and copy the file over.*

Foreach does not work if are wanting to loop through the library and delete items.

UPDATE

In this example, I’m using a CAML query to find all documents created before 01/01/2014. This example will also process the items in batches, cutting down on server load. When working with CAML queries, be mindful of the ‘ and ” characters.

$web = Get-SPWeb "http://sharepointed.com/"
$list = $web.Lists["Shared Documents"]

$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewAttributes = "Scope='Recursive'";
$spQuery.RowLimit = 2000
$caml = '<Where><Lt><FieldRef Name="Created" /><Value IncludeTimeValue="TRUE" Type="DateTime">2014-01-01T04:06:45Z</Value></Lt></Where> '
$spQuery.Query = $caml 

do
{
    $listItems = $list.GetItems($spQuery)
    $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
	$listTotal = $listItems.Count

	for ($x=$listTotal-1;$x -ge 0; $x--)
	{
		try
			{
				$listItems[$x].CopyTo("http://sharepoint/Docs/Documents/"+ $listItems[$x].name)
				Write-Host("DELETED: " + $listItems[$x].name)
				$listItems[$x].Recycle()
			}
		catch
			{
			Write-Host $_.Exception.ToString()
			}
	}
}
while ($spQuery.ListItemCollectionPosition -ne $null)
Posted in Powershell, SharePoint | Tagged copy files, metadata, powershell, sharepoint | 13 Replies
Privacy Policy Proudly powered by WordPress