Hidden objects in SharePoint "Explorer View"

Imagine the following scenario: a user creates a folder in SharePoint Document Library and gives it a name starting with the underscore (_) character. When you then open the Document Library in Windows Explorer, the folder will not be visible if the option  is not enabled in Windows Explorer:

"Show hidden files, folders and drives"

This behavior is expected (it dates back to the days of FrontPage 2000) and is also usually the reason why the folder was named with a leading underscore.

However, if the folder is then renamed and the underscore is removed, the folder will still remain hidden in "Explorer View". This is why:

Windows Explorer communicates with SharePoint over WebDAV. For each object stored in SharePoint and browsed from Windows Explorer, the Win32FileAttributes property is sent over the wire:

Request:

PROPFIND <DocLib_URL>

[...]

Depth:1

Response:

207 MULTI-STATUS

[...]

<D:prop><D:displayname>_hidden_folder</D:displayname>[...]<D:isFolder>t</D:isFolder>[...]<Z:Win32FileAttributes>00000016</Z:Win32FileAttributes></D:prop>

[...]

 

The value of Win32FileAttributes (specified in the Microsoft Extensions to the WebDAV protocol) informs Windows Explorer to treat this folder as hidden. In SharePoint, this property is stored in the SPFolder object's property bag:

$folder = (Get-SPWeb https://url).Folders["DocLib_Name"].SubFolders["_Folder_with_underscore"] $folder.Properties["vti_winfileattribs"]

It is not automatically removed when the folder is renamed, but can be manually reset using:

$folder.Properties["vti_winfileattribs"]=""