SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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()}
share|improve this answer

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 !!!

share|improve this answer
Hello Shahjinesh11, How can I use this code to work? I've never used code for SharePoint before.. – Igor Batoukhtine Aug 10 '12 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.… – J.Shah Aug 13 '12 at 11:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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