I want to copy a folder from one document library to another document library and maintain permissions on the folder structure. When I CUT the folder and paste it the permissions on the folder structure are maintained. When I want to COPY the folder and paste it, the folder inherits the permissions all over again. How can I resolve this?

Does somebody have an answer to this?

3 Answers 3


This is a powershell script which copies all the folders and its content from one list(source list) to a new list (dest list) with required permissions.

Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

function Copy-ItemsToFolder([Microsoft.SharePoint.SPFolder]$folder, $srcList, $destList)
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.Folder = $folder

$sourceSPListItemCollection = $srcList.GetItems($spQuery);
$destFolder = $destList.Folders[$folder.Name];
if ($destFolder -eq $null -or $destFolder -eq "")
    #folder does not exist so create it.
    $destFolder = $destList.AddItem("", [Microsoft.SharePoint.SPFileSystemObjectType]::Folder)
    $destFolder["Title"] = $folder.Name;
$count = $sourceSPListItemCollection.Count;
$index = 0;
$newFolderPath = $destFolder.Folder.ServerRelativeUrl
foreach($srcListItem in $sourceSPListItemCollection)

    write-host "adding new item $index of $count";
    $newSPListItem = $destList.AddItem($newFolderPath, [Microsoft.SharePoint.SPFileSystemObjectType]::File, $null);

    foreach($spField in $srcListItem.Fields)
        if ($spField.ReadOnlyField -ne $True -and $spField.InternalName -ne "Attachments")
            $newSPListItem[$spField.InternalName] = $srcListItem[$spField.InternalName];
    write-host "added";
$srcListSiteUrl = "https://sourcesite/ad/"
$SourceListName = "SiteSourceList"

$dstListSiteUrl = "https://destsite/BgP/"
$DestinationListName = "SiteDestArchive"

$keyColumnInternalName = "Title"

$sourceListWeb = Get-SPWeb -identity $srcListSiteUrl
$sourceListUrl = $sourceListWeb.ServerRelativeUrl + "/lists/" + $SourceListName;

$dstListWeb = Get-SPWeb -identity $dstListSiteUrl
$destinationListUrl = $dstListWeb.ServerRelativeUrl + "/lists/" + $DestinationListName;

$SourceList = $sourceListWeb.GetList($sourceListUrl);
$DestinationList = $dstListWeb.GetList($destinationListUrl);

foreach($currentFolder in $SourceList.RootFolder.SubFolders)
    Write-Host "processing folder $($currentFolder.Name)";

    if ($currentFolder.ItemCount -gt 0)
        Copy-ItemsToFolder $currentFolder $SourceList $DestinationList
    Write-Host "done with folder"

write-host $_.exception

if($sourceListWeb -ne $null){$sourceListWeb.Dispose()}
if($dstListWeb -ne $null){$dstListWeb.Dispose()}
  • your script looks really great, but did you wirte something to do the same operation for sharepoint online?
    – John John
    Commented Jul 10, 2019 at 21:47

You can try this code, CopyItemPermission:

        using (SPSite site = new SPSite("http://yoursite"))
            using (SPWeb web = site.OpenWeb())
                SPList sourceList = web.Lists.TryGetList("SourceLibrary");
                SPList targetList = web.Lists.TryGetList("TargetLibrary");

                SPListItem sourceItem = sourceList.GetItemById(47);
                SPFolder sourceFolder = sourceItem.Folder;
                string targetPath = targetList.RootFolder.ServerRelativeUrl + "/" + sourceFolder.Name;

                SPFolder targetFolder = web.GetFolder(targetPath);
                SPListItem targetItem = targetFolder.Item;

                CopyItemPermission(sourceItem, targetItem);

    public static void CopyItemPermission(SPListItem SourceItem, SPListItem TargetItem)
            if (SourceItem.HasUniqueRoleAssignments)

            while (TargetItem.RoleAssignments.Count > 0)
            //copying all the permission from source item to target item
            foreach (SPRoleAssignment role in SourceItem.RoleAssignments)

Happy Coding !!!

  • Hello Shahjinesh11, How can I use this code to work? I've never used code for SharePoint before.. Commented Aug 10, 2012 at 12:43
  • Hi Igor, Sorry for late reply. You can create custom webpart or layout page in sharepoint. Also, you can buy kind of product and you can use it if you dont want to create it. example.macroview.com.au/products/pages/…
    – J.Shah
    Commented Aug 13, 2012 at 11:57
  • is it possible in SharePoint online?? any code is appreciated Commented May 21, 2019 at 15:38
  • @sandy143 i have the same case, i need to find a pnp script to move files/folders in SP online..
    – John John
    Commented Jul 10, 2019 at 14:29
  • @J.Shah thanks for the great post ,, but did you have similar script which can work with sharepoint online?
    – John John
    Commented Jul 10, 2019 at 21:48

I was able to achieve the same in SharePoint online but we need to minimize the code. Please try and let me know your views

How to copy the folder structure and permissions with in the same library

  • has any one tried ... please vote it and let me know if any difficulty Commented Jul 15, 2019 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.