We had a situation come up where we had taken down a SharePoint server and of course all of the users said they had everything they needed from it until 3 weeks later when several documents were found “conveniently missing”. All we had left were the databases from the installation and I found a really good script to extract documents from your database.
This script goes directly against a MOSS 2007 content database which is generally discouraged. Any code using the database directly will not be supported by MS Product Support Services. Instead, the SharePoint and WSS APIs are the way to go. If the database is modified directly rather than through the published SharePoint and WSS APIs Product Support Services cannot properly troubleshoot any unexpected issues. This script reads from the database so we’re safe from errant modifications. However, the data structure the script queries could change in a future service pack.
Here is the script we used and you can copy and paste this into Notepad and save it as ex “extractdoc.vbs”.
server = “server name”
contentDatabase = “database name”
leaf = “filename”
outputPath = “C:\Temp\filename”
ExtractDoc server, contentDatabase, leaf, outputPath
Sub ExtractDoc(server, contentDatabase, leaf, outputPath)
Dim conStr, selectStr
conStr = “Provider=SQLOLEDB;data Source=” + server + “;Initial Catalog=” + contentDatabase + “;Trusted_Connection=yes”
selectStr = “SELECT dbo.AllDocStreams.Content FROM dbo.AllDocs ”
selectStr = selectStr + “INNER JOIN dbo.AllDocStreams ”
selectStr = selectStr + ” ON dbo.AllDocs.ID= dbo.AllDocStreams.ID ”
selectStr = selectStr + ” AND dbo.AllDocs.Level = dbo.AllDocStreams.Level ”
selectStr = selectStr + ” where LeafName='” + leaf +”‘ AND IsCurrentVersion=1″
Set cn = CreateObject(“ADODB.Connection”)
Set rs = CreateObject(“ADODB.Recordset”)
Set rs = cn.Execute(selectStr)
Set mstream = CreateObject(“ADODB.Stream”)
mstream.Type = 1
mstream.SaveToFile outputPath, 2
This took some research to find but it worked like a charm. Simply replace the server name, database name and filename fields with the appropriate values and you’re good to go. The filenames unfortunately have to be exact or it will not find it. Also, be sure to include the extension with the filename.
Hope this helps!