Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

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)
share|improve this answer
    
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 –  Mala Singha Sep 14 '11 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). –  Tim Gabrhel Sep 14 '11 at 20:24
    
Actually the error on this line $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($docLib.R‌​ootFolder,$DocSet,$cType.Id,$docsetProperties) –  Mala Singha Sep 14 '11 at 20:37
    
I have bunch of comments that's why my line and posted line are out of sync –  Mala Singha Sep 14 '11 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. –  Tim Gabrhel Sep 14 '11 at 20:47
show 5 more comments

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.

share|improve this answer
add comment

Your Answer

 
discard

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.