0

I am receiving this error on following line

Exception calling "Create" with "4" argument(s): "Value cannot be null. Parameter name: parentFolder" At x:\Dev\PowerShell\MoveFiles2DocSet.ps1:29 char:91 + $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create <<<< ($docLib.RootFo lder,$DocSet,$cType.Id,$docsetProperties) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($docLib.RootFolder,$DocSet,$cType.Id,$docsetProperties)

$siteURL="http://intranet.colgate.com/sites/blazingWhite"          
$docLib = "NewProduct"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$collFiles=$web.GetFolder($docLib).Files
$count=$collFiles.Count
while($count -ne 0)
{
$item = $collFiles[$count-1].Item
## Create document set if it does not exists
$DocSet = $item["CounterParty"]
$DocSetURL = $siteURL + "/" + $docLib + "/" + $DocSet
$docLibURL = $siteURL + "/" + $docLib
[Microsoft.SharePoint.SPFolder]$targetFolder = $web.GetFolder($DocSetURL)
[Microsoft.SharePoint.SPFolder]$doclibFolder = $web.GetFolder($docLibURL)
Write-Host ""
Write-Host $DocSet
Write-Host $targetFolder
Write-Host $doclibFolder

  if (-not $targetFolder.Exists)
    {   # Create Doc Set    
        # Get Document Set Content Type from list   
            $cType = $web.ContentTypes["Document Set"]
        # Create Document Set Properties Hashtable          
            [Hashtable]$docsetProperties = @{"Title"=$DocSet}
            $docsetProperties = @{"Description"=$DocSet}
            $docsetProperties = @{"CounterParty"=$DocSet}

            Write-Host $cType.Id   
            Write-Host $docsetProperties
            Write-Host ""
        # Create new Document Set

        $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($doclibFolder,$DocSet,$cType.Id,$docsetProperties)
        Write-Host "Document set created " $newDocumentSet

        if($newDocumentSet.Exists)
        {
            # changing folder type to Document Set type
            $newDocumentSet.Item["ContentTypeId"] = $cType.Id
            $newDocumentSet.Item["HTML File Type"] = "SharePoint.DocumentSet"
            $newDocumentSet.Item.Update()
        }

    } 

# move file(s) to the document set
    Write-Host "$DocSet is the doc set. $collFiles[$count-1].Name is name"
    $collFiles[$count-1].MoveTo($siteURL + "/" + $docLib + "/" + $DocSet + "/"  + $collFiles[$count-1].Name, $true)                       
$count--
}

#dispose:
    $web.Dispose();    
    $site.Dispose();

Edit:

The above code is working except document set looks like Folder instead of blue doc set icon. Can anyone shed some light on this please.

2 Answers 2

0

Just by looking at your code.

Create($docLib.RootFolder,$DocSet,$cType.Id,$docsetProperties)

and $docLib is string?

$docLib = "NewProduct"

maybe this would work

Create($targetFolder,$DocSet,$cType.Id,$docsetProperties)

since

[Microsoft.SharePoint.SPFolder]$targetFolder = $web.GetFolder($DocSetURL)
10
  • hmm. still gettting same error. Exception calling "Create" with "4" argument(s): "<nativehr>0x80070002</nativehr><nativestack></nativestack>" At C:\Dev\PowerShell\MoveFiles2DocSet.ps1:38 char:91 + $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create <<<< ($targetFolder, $DocSet,$cType.Id,$docsetProperties) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException Sep 14, 2011 at 20:19
  • Please update your original question with an updated code sample to reflect Vedran's solution. Your code above does not have 38 lines (though your error occurs at line 38). Sep 14, 2011 at 20:24
  • Actually the error on this line $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($docLib.RootFolder,$DocSet,$cType.Id,$docsetProperties) Sep 14, 2011 at 20:37
  • I have bunch of comments that's why my line and posted line are out of sync Sep 14, 2011 at 20:38
  • Well Verdan has you on the right track. First, make sure none of your parameters are null (write them out to the screen to ensure their values), and make sure that their types are correct. Sep 14, 2011 at 20:47
0

I'm kind of late to this particular party, but while researching my own issue with document sets appearing as simple folders I came across this blog entry ( http://aknauer.blogspot.com/2011/06/document-sets-und-powershell.html ) which contained this valuable nugget:

"It is also important that you select the content type $cType from the collection of the list and not from the collection of the Web. Otherwise, rather than just a document set a new folder is created."

I switched my content type assignment from the web collection (as Mala had done) to the list collection (as Andreas suggests) and my problem was resolved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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