Windows SharePoint Services File System and “Customized” Pages

Introduction

WSS File System is represented by pair of tables: “dbo.AllDocs” and “dbo.AllDocStreams”. “dbo.AllDocs” table is a file system itself. “dbo.AllDocStreams” contains binary data of uploaded files. “Customized” or “Unghosted” pages are saved into WSS File System instead of hard drive. This document shows the way of how to return them back to the physical disk.

Audience

This document can be used by programmer as a reference.

File System

WSS File System is described by dbo.AllDocs table.

Hierarchy

The following two columns create WSS File System hierarchy:

·         Id

·         ParentId

Virtual Path

Virtual path to the File System resource is a combination of the following two columns:

·         DirName – path to the resource

·         LeafName – resource name

For example:

·         DirName=”_catalogs/masterpage” and  LeafName=”default.master” for “_catalogs/masterpage/default.master” path

·         DirName=”_catalogs” and  LeafName=”masterpage” for “_catalogs/masterpage” path

·         DirName=”” and  LeafName=”_catalogs” for “_catalogs” path

Resource Type

“Type” column contains 0 for file and 1 for folder. It has 2 for root folder (DirName=”” and  LeafName=””).

File Size

“Size” column has file size in bytes and NULL for folder.

Resource Location

Column “DocFlags” has 268 for resources located on hard drive and 332 for resources located inside dbo.AllDocStreams table.

If DocFlags=268 then resource is taken from file system, using path from SetupPath column. That path is a relative path to the “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE” folder. For example: SetupPath=”global\default.master” means “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\global\default.master”.

Changing Master Page

1.       Upload any custom built Master Page into “Master Page Gallery”.

 Click Site Actions -> Site Settings -> Galleries -> Master Pages -> Upload -> Browse

I saved a copy of “Global\Default.master” file as “Global\vitaly.master” and modified “vitaly.master”, adding word “WssFileSystem” immediately after <body> element for this example.

Uncheck “Add as a new version to existing files” and don’t fill “Version Comments”.

I uploaded “vitaly.master” file for example.

As a result, uploaded master page appeared inside dbo.AllDocs table under “_catalogs/masterpage” folder. You can check that running the following statement:

SELECT

      DirName,

      LeafName

FROM

      dbo.AllDocs

WHERE

      DirName='_catalogs/masterpage' AND

      Type=0

 

It returned the following two entries for my example:

DirName

LeafName

_catalogs/masterpage

default.master

_catalogs/masterpage

vitaly.master

 

2.       Change Site Master Page

There are two options to do that:

a)      Swap LeafName values, that is rename “default.master” to “vitally.master” and “vitally.master” to “default.master”:

-- Rename default.master into default_original.master

UPDATE

      dbo.AllDocs

SET

      LeafName='default_original.master'

WHERE

      DirName='_catalogs/masterpage' AND

      LeafName='default.master'

-- Rename vitaly.master into default.master

UPDATE

      dbo.AllDocs

SET

      LeafName='default.master'

WHERE

      DirName='_catalogs/masterpage' AND

      LeafName='vitaly.master'

-- Rename default_original.master into vitaly.master

UPDATE

      dbo.AllDocs

SET

      LeafName='vitaly.master'

WHERE

      DirName='_catalogs/masterpage' AND

      LeafName='default_original.master'

 

This is a “dirty” way because you need to remember that original “default.master” is stored as “vitaly.master” from now on.

 

b)      Change MasterUrl value from “_catalogs/masterpage/default.master” to “_catalogs/masterpage/vitaly.master” inside dbo.Webs table:

SELECT

      MasterUrl

FROM

      dbo.Webs

 

MasterUrl

_catalogs/masterpage/default.master

 

-- Change master page

UPDATE

      dbo.Webs

SET

      MasterUrl='_catalogs/masterpage/vitaly.master'

WHERE

      MasterUrl='_catalogs/masterpage/default.master'

 

SELECT

      MasterUrl

FROM

      dbo.Webs

 

MasterUrl

_catalogs/masterpage/vitaly.master

 

After refreshing SharePoint site I saw word “WssFileSystem” at left top corner of the screen.


Placing Master Page on Hard Drive

Continuing with above example, let place “vitally.master” file on physical disk as “Vitaly\vitaly.master”.

I created “Vitaly” folder under “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\”, saved a copy of “Global\Default.master” file as “Vitaly\vitaly.master” and modified “vitaly.master”, adding word “LocalDisk” immediately after <body> element for this example.

Redirect SharePoint to File System

1.       We need to provide “SetupPath” – physical path to the file on hard drive. In our case it is “Vitaly\vitaly.master”.

2.       We need to change the value of “DocFlags” column from 332 (which forces SharePoint to take file from dbo.AllDocStreams table) to 268. If DocFlags=268 then resource is taken from local disk, using path from SetupPath column.

 

UPDATE

      dbo.AllDocs

SET

      DocFlags=268

      SetupPath='Vitaly\vitaly.master'

WHERE

      LeafName='vitaly.master'

 

After refreshing SharePoint site I saw word “LocalDisk” at left top corner of the screen.

 

Now there are two “vitaly.master” files. One is on the local disk and second is inside dbo.AllDocStreams table. It is easy to switch between them changing “DocFlags” value:

 

-- Show file from dbo.AllDocStreams table

UPDATE

      dbo.AllDocs

SET

      DocFlags=332

WHERE

      LeafName='vitaly.master'

 

After refreshing SharePoint site I saw word “WssFileSystem” at left top corner of the screen.

 

-- Show file from file system

UPDATE

      dbo.AllDocs

SET

      DocFlags=268

WHERE

      LeafName='vitaly.master'

 

After refreshing SharePoint site I saw word “LocalDisk” at left top corner of the screen.

Conclusion

It is easy to specify to SharePoint where it should take a resource from – WSS File System or local dick.

Vitaly Laskarzhevsky

2007-09-05