The General Theory of RIAtivity

Pondering the New Fabric of the Web — Rich Internet Applications (RIAs)

Archive for June 2008

ASP Script to Save All Documents from a Sharepoint DB

with 3 comments

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”)
%>

Written by riactant

14-June-2008 at 16:06