Recovering Documents directly from the database

I came across this tip a few months ago, but today I had to use it again for a client’s assistance. It is not the common tip or you won’t use it often, but it is good to know . . .

If you need to ever extract a file manually out of WSS/SPS, this is how you do it:
1) Find the right row. Everything is in the DOCS table (_SITE Database), and there is a DirName property that you can use to find it based on a relative path. Something like this will work.
WHERE (DirName LIKE ‘sites/sitename/Shared Documents%’)
2) From there, grab the ID guid. Save the following to a local .vbs file, and replace the servername, database name, GUID and filename.
Set cn = WScript.CreateObject(“ADODB.Connection”)
cn.Open “Provider=SQLOLEDB;data Source=SERVERENAME;Initial Catalog=WSS or SPS SITE DB name;Trusted_Connection=yes”
Set rs = WScript.CreateObject(“ADODB.Recordset”)
rs.Open “Select content from docs where id='{guid goes here}'”, cn
Set mstream = WScript.CreateObject(“ADODB.Stream”)
mstream.Type = 1
mstream.Write rs.Fields(“content”).Value
mstream.SaveToFile “c:\filename goes here”, 2

Hope it helps!!!!

Computer developer/consultant from Portugal. You can find me at

Posted in Sharepoint
One comment on “Recovering Documents directly from the database
  1. Old post but still really helpful.

    Thanks, Ricardo.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: