Two months ago Microsoft published an update for the WebDAV module that shipped with IIS 7.5 in Windows 7 and Windows Server 2008 R2, and this update is documented in the Microsoft Knowledge Base article ID 2593591:
This update enables administrators to configure the IIS 7.5 WebDAV module to store WebDAV-based properties in NTFS alternate data streams instead of properties.dav files. By way of explanation, WebDAV has two HTTP methods – PROPFIND and PROPPATCH – which enable WebDAV clients to store custom properties on a WebDAV server. These properties may contain anything that makes sense to the WebDAV client. For example, if you were creating a WebDAV client that stored Microsoft Office documents on a WebDAV server, you could store metadata in WebDAV properties for each document, like the author’s name, document abstract, etc.
By default, the IIS 7.5 WebDAV module stores properties in system files in each folder of a website that are called properties.dav. These files are essentially text-based INI files that contain the encoded WebDAV properties for the various files in each folder. In contrast, the WebDAV functionality in IIS 6 had used NTFS alternate data streams to store WebDAV properties, which are described in the following Microsoft TechNet article:
After we shipped IIS 6, we received a lot of complaints from customers who were losing their WebDAV properties when they were copying their website files between NTFS and FAT file systems. This was expected behavior – NTFS alternate data streams will be removed when you copy files from NTFS to FAT. To remedy this situation, in IIS 7.0 we decided to switch to using INI-based functionality in order to prevent losing custom WebDAV properties when files are copied between disparate file systems.
When we were designing IIS 7.5, we wanted to add optional support for storing WebDAV properties in NTFS alternate data streams, and we wanted to do so because NTFS alternate data streams might perform faster when you are working with larger websites; however, we ran out of time to implement that functionality before we shipped Windows 7 and Windows Server 2008 R2. That being said, we still wanted to implement the feature, and the update that I listed at the beginning of this blog contains the functionality that is required to enable storing WebDAV properties in NTFS alternate data streams.
Enabling Alternate Data Streams for WebDAV Properties
The above information is good news for anyone who is storing large quantities of WebDAV properties, so your next logical question might be: “How do I enable NTFS alternate data streams for WebDAV properties ?”
Actually, it’s really simple. In the KB article that I listed in the beginning of this blog, I documented two methods that show you how to enable storing WebDAV properties in NTFS alternate data streams:
- By modifying your applicationHost.config file
- By using AppCmd.exe
For the sake of completeness, I will repost some of the information here.
Method #1: Modifying your applicationHost.config file
You can enable storing WebDAV properties in alternate data streams for the simple property provider by adding a “useAlternateDataStreams” attribute to the property provider’s registration settings in your applicationHost.config file, which is highlighted in the following global configuration snippet:
<webdav> <globalSettings> <propertyStores> <add name="webdav_simple_prop" image="%windir%\system32\inetsrv\webdav_simple_prop.dll" image32="%windir%\syswow64\inetsrv\webdav_simple_prop.dll" useAlternateDataStreams="true" /> </propertyStores> <lockStores> <add name="webdav_simple_lock" image="%windir%\system32\inetsrv\webdav_simple_lock.dll" image32="%windir%\syswow64\inetsrv\webdav_simple_lock.dll" /> </lockStores> </globalSettings> <authoring> <locks enabled="true" lockStore="webdav_simple_lock" /> <properties> <clear /> <add xmlNamespace="*" propertyStore="webdav_simple_prop" /> </properties> </authoring> <authoringRules /> </webdav>
Once you have enabled the feature, you have to restart IIS in order for it to take effect.
Method #2: Using AppCmd.exe
I wrote the following batch file for the KB article, which uses AppCmd.exe to enable the NTFS alternate data streams functionality, and it automatically restarts IIS for you:
appcmd.exe set config -section:system.webServer/webdav/globalSettings -propertyStores.[name='webdav_simple_prop'].useAlternateDataStreams:true /commit:apphost
Migrating IIS 7 WebDAV Properties into Alternate Data Streams
Once you’ve enabled storing WebDAV properties in alternate data streams, you are presented with a new challenge: “How do I migrate my existing WebDAV properties?”
Here’s the situation, once you have enabled the alternate data streams feature, the WebDAV property provider is going to ignore any properties that have already been set in properties.dav files. With this in mind, I wrote a script that will migrate all of the WebDAV properties from all of the properties.dav files in a website into their corresponding per-file NTFS alternate data streams.
To use the following script, you will need to update the folder path in the third line of the script with the path to your website. Once you have done that, you can run the script to migrate your existing WebDAV properties.
NOTE: You need to run this script as an administrator!
Option Explicit Dim arrFolderTree, intFolderCount arrFolderTree = BuildFolderTree("C:\inetpub\wwwroot") For intFolderCount = 1 To UBound(arrFolderTree) MigratePropertiesToADS arrFolderTree(intFolderCount) Next Sub MigratePropertiesToADS(strFolderPath) On Error Resume Next ' Declare all our variables Dim objTempFSO, objTempFolder Dim objTempPropertiesFile, objTempAlternateDataStream Dim strTempLine, strTempObjectName, blnTempOpenStream Const strTempPropertiesDAV = "\properties.dav" Const strTempAlternateDataStream = ":properties.dav:$DATA" ' Create a file system object. Set objTempFSO = WScript.CreateObject("Scripting.FileSystemObject") ' Flag the function as having a closed output stream. blnTempOpenStream = False ' Retrieve a folder object for the path. Set objTempFolder = objTempFSO.GetFolder(strFolderPath) ' Check for a properties.dav file in the current folder. If objTempFSO.FileExists(objTempFolder.Path & strTempPropertiesDAV) Then ' Open the properties.dav file for the current folder. Set objTempPropertiesFile = objTempFSO.OpenTextFile(objTempFolder.Path & _ strTempPropertiesDAV,1,False,-1) ' Loop through the properties.dav file. Do While Not objTempPropertiesFile.AtEndOfStream ' Retrieve a line from the properties.dav file. strTempLine = Trim(objTempPropertiesFile.ReadLine) ' Check if it's a section heading. If Left(strTempLine,1) = "[" And Right(strTempLine,1) = "]" Then ' Parse the name of the object (file/folder). strTempObjectName = Replace(Trim(Mid(strTempLine,2,Len(strTempLine)-2)),"/","\") ' Strip off a backslash from the parent folder. If Len(strTempObjectName) = 1 Then strTempObjectName = "" ' Check to see if the file/folder exists. If objTempFSO.FileExists(objTempFolder.Path & _ strTempObjectName) Or objTempFSO.FolderExists(objTempFolder.Path & _ strTempObjectName) Then ' Create a file object for the alternate data stream. Set objTempAlternateDataStream = objTempFSO.CreateTextFile(objTempFolder.Path & _ strTempObjectName & _ strTempAlternateDataStream,True,-1) ' Write the WebDAV section header. objTempAlternateDataStream.WriteLine "[WebDAV]" ' Flag the function as having an open output stream. blnTempOpenStream = True Else ' Flag the function as having a closed output stream. blnTempOpenStream = False End If Else ' Check if we have an open output stream. If blnTempOpenStream = True Then ' Output a property. objTempAlternateDataStream.WriteLine strTempLine End If End If Loop ' Close the properties.dav file. objTempPropertiesFile.Close End If Set objTempFSO = Nothing End Sub Function BuildFolderTree(strTempBaseFolder) On Error Resume Next ' Declare all our variables Dim objTempFSO Dim objTempFolder Dim objTempSubFolder Dim lngTempFolderCount Dim lngTempBaseCount ' Create our file system object. Set objTempFSO = WScript.CreateObject("Scripting.FileSystemObject") ' Define the initial values for our folder counters. lngTempFolderCount = 1 lngTempBaseCount = 0 ' Dimension an array to hold the folder names. ReDim strTempFolders(1) ' Store the root folder in our array. strTempFolders(lngTempFolderCount) = strTempBaseFolder ' Loop while we still have folders to process. While lngTempFolderCount <> lngTempBaseCount ' Set up a folder object to a base folder. Set objTempFolder = objTempFSO.GetFolder(strTempFolders(lngTempBaseCount+1)) ' Loop through the collection of subfolders for the base folder. For Each objTempSubFolder In objTempFolder.SubFolders ' Increment our folder count. lngTempFolderCount = lngTempFolderCount + 1 ' Increase our array size ReDim Preserve strTempFolders(lngTempFolderCount) ' Store the folder name in our array. strTempFolders(lngTempFolderCount) = objTempSubFolder.Path Next ' Increment the base folder counter. lngTempBaseCount = lngTempBaseCount + 1 Wend ' Return the array of folder names. BuildFolderTree = strTempFolders End Function
I have a couple final notes for you to consider:
- Enabling NTFS alternate data streams is a global WebDAV setting; you cannot do this on a per-site basis.
- As with IIS 6, once you enable storing WebDAV properties in NTFS alternate data streams, you will lose your WebDAV properties if you copy your files between NTFS and FAT file systems.