SharePoint mixing up Folders and Document Sets with WebDAV

When you create a document library, the document library (by default) has two content types – Document, and Folder. Folder is hidden from you – but when you list the content types of the library in Powershell, the following will be reported:

  • Document
  • Folder

When you create a folder in WebDAV, the Folder Content Type is chosen by SharePoint automatically. Interestingly, if you use powershell to remove the Folder content type, and then create another folder via WebDAV, it will have NO content type listed, even though the folder will still work as a folder in the library.

Here’s the catch – and how you can confuse SharePoint:

If you remove the Folder Content Type, and add a Document Set Content Type, and then go to WebDAV to create a folder, the folder will get the Document Set content type. The reason for this appears to be in the way SharePoint chooses the folder content type – Folders and Document Set IDs (GUIDs) both begin “0x0120”. It looks like SharePoint finds the document set content type, and uses it for the folder. It even does it if you add the folder content type back, which points towards SharePoint interrogating the content types in the order they were applied to the library.

The solution is to re-write the UniqueContentTypeOrder for the RootFolder of the library. It is a generic list of Content Type IDs – and you must be careful to use the IDs of the List Content Types – not the Web or Site Content Types, because their GUIDs will differ.

Posted by Jonathan Beckett in Notes, 0 comments

Bulk Uploading Files into Libraries in SharePoint with PowerShell

The following snippet shows a method of uploading a folder of files on the filesystem into a library in SharePoint. In this case the filesystem folder is presumed to exist in the same location as the PowerShell script, called “SiteAssets”, uploading to a library in the SharePoint subsite called “SiteAssets”.

# Connect to SharePoint Site
$web = get-spweb "https://server/sites/site_collection/subsite"

# loop through all files in the local siteassets subfolder
foreach ( $source_file in $(Get-ChildItem './SiteAssets' | Sort-Object -Property Name) ) {
    if ($source_file.Attributes -match 'Directory') {
        # its a folder - ignore it
    } else {
        $library = $web.GetFolder("SiteAssets")
        $library_files = $library.Files

        $file = Get-ChildItem $source_file.FullName

        $library_files.Add("SiteAssets/" + $source_file.Name,$file.OpenRead(),$true) > $null

# Release resources
Posted by Jonathan Beckett in Notes, 0 comments