Credit goes to Ryan Spletzer: http://sharepoint.stackexchange.com/questions/79294/spcopydestinationcollection-add-method-does-not-persist-to-the-database
Anyways, here's the code:
function CreateManagedCopy($sourceWebUrl,$sourceRelativeFileUrl,$destinationUrl) { Start-SPAssignment -AssignmentCollection $current $web = get-spweb $sourceWebUrl -AssignmentCollection $current $updatetype = [Microsoft.SharePoint.SPCopyDestinationType]::Update $sourcefile = $web.GetListItem($sourceRelativeFileUrl); $sourcefile.CopyTo($destinationUrl) $sourcefile.CopyDestinations.Add($destinationUrl, $updatetype, "Copied from PowerShell") $sourcefile.UpdateOverwriteVersion() } # To call the function: # CreateManagedCopy "https://intranet/sites/test" "/sites/test/libA/test.docx" "https://intranet/sites/test/moveTo/test10.docx"
No comments:
Post a Comment