1

I need to create bulk folder(~200) in document library. I have tried using console application but it required more time to create then i have decided to create using batch processing as suggested in this Post.

Here is my code

StringBuilder query = new StringBuilder();
query.AppendFormat("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ows:Batch Version=\"6.0.2.5608\" OnError=\"Return\">");
for (int itemIx = 0; itemIx < 100; itemIx++)
{
    query.AppendFormat("<Method ID=\"{0}\" >" +
    "<SetList>{1}</SetList>"+
    "<SetVar Name=\"FSObjType\">1</SetVar>" +
    "<SetVar Name=\"Cmd\">Save</SetVar>" +
    "<SetVar Name=\"BaseName\">MyFolder{0}</SetVar>" +
    "<SetVar Name=\"ID\">New</SetVar>" +
    "</Method>", itemIx,doclib.ID);
}

query.AppendFormat("</ows:Batch>");

web.ProcessBatchData(query.ToString());

But somehow this is not working. It doesn't create any folder or not return any error from code block.

Or suggest me any other way to create bulk folder in less time.

1 Answer 1

0

Here's how I did it:

$Installed=Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.PowerShell" }
if ($Installed -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" }

$FolderNames=@("One","Two","Three")

$TargetWebURL="http://<url to site>"
$TargetWeb=Get-SPWeb -Identity $TargetWebURL
$TargetLibrary="<Library Name>"
$CI=[Microsoft.SharePoint.SPFolderCreationInformation]::new()
$SPPath=[Microsoft.SharePoint.SPResourcePath]::FromUri($TargetFolder.ServerRelativePath)
$FolderNames | ForEach-Object { $Folder=$TargetFolder.SubFolders.Add($_); $Folder.Update() }

Caveats:

  1. Local SharePoint
  2. Ran as credentials that already had sufficient permissions
  3. SharePoint 2019
  4. PowerShell 5.1

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.