Archive for June 2008
ASP Script to Save All Documents from a Sharepoint DB
Here’s an ASP script I’ve written that extracts all documents from a Sharepoint (MOSS 2007) site database. I used this when I corrupted a Sharepoint instance of mine but the DB was still intact. Use at your own risk.
<% response.buffer = true
Set cn = CreateObject(“ADODB.Connection”)
cn.Open “Provider=SQLOLEDB;data Source=<SQL Server DB\instance name here>;” _
& “Initial Catalog=<the DB name of your WSS_Content DB>;” _
& “User Id=<DB username here>;Password=<DB password here>”
Set rs = CreateObject(“ADODB.Recordset”)
rs.Open “Select LeafName, Content from ” _
& “AllDocs,AllDocStreams where AllDocs.id = AllDocStreams.id”, cn, 1, 3
‘Loop through the Recordset
Do While Not rs.EOF
Set mstream = CreateObject(“ADODB.Stream”)
mstream.Type = 1
mstream.Open
mstream.Write rs.Fields(“content”).Value
filePath = “c:\<some path that has IUSR write access here” & rs.Fields(“LeafName”)
mstream.SaveToFile filePath, 2
mstream.close
set mstream = nothing
rs.MoveNext
Loop
rs.Close
cn.Close
set rs = nothing
set cn = nothing
Response.Write(“done”)
%>
