22.2.06

Sharepoint Tip - 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.
SELECT *
FROM Docs
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.Open
mstream.Write rs.Fields("content").Value
mstream.SaveToFile "c:\filename goes here", 2
rs.Close
cn.Close

Hope it helps!!!!