0

我有一个 Sharepoint 的数据库 (WSS_Content),但没有安装 sharepoint,我需要它的数据。您检索数据的解决方案是什么?我应该编写一个转换器来将文件/链接/站点数据从二进制数组中提取为数据还是有更简单的方法?我可以安装一个新的共享点并使用这个数据库吗?

4

2 回答 2

2

我挖掘了一个我不久前使用的旧应用程序,它可以从内容数据库中提取所有文档的基本内容。它没有任何选择性,它只是抓住那里的任何东西。然后,您可以选择输出以获取所需的内容。

我相信原始代码来自其他人(我不记得在哪里,所以不能相信他们)。我只是稍微破解了它。随意试一试。

它只是直接访问数据库,因此您只需将它安装在 SQL Server 中。不需要 SharePoint 服务器。

using System;
using System.Data.SqlClient;
using System.IO;

namespace ContentDump
{
    class Program
    {
        // Usage: ContentDump {server} {database}
        //
        static void Main(string[] args)
        {
            string server = args[0];
            string database = args[1];
            string dbConnString = String.Format("Server={0};Database={1};Trusted_Connection=True;", server, database);

            // create a DB connection
            SqlConnection con = new SqlConnection(dbConnString);
            con.Open();

            // the query to grab all the files.
            SqlCommand com = con.CreateCommand();
            com.CommandText = "SELECT ad.SiteId, ad.Id, ad.DirName," +
                " ad.LeafName, ads.Content" +
                " FROM AllDocs ad, AllDocStreams ads" +
                " WHERE ad.SiteId = ads.SiteId" +
                " AND ad.Id = ads.Id" +
                " AND ads.Content IS NOT NULL" +
                " Order by DirName";

            // execute query
            SqlDataReader reader = com.ExecuteReader();

            while (reader.Read())
            {
                // grab the file’s directory and name
                string DirName = (database + "/" + (string)reader["DirName"]).Replace("//", "/");
                string LeafName = (string)reader["LeafName"];

                // create directory for the file if it doesn’t yet exist
                if (!Directory.Exists(DirName))
                {
                    Directory.CreateDirectory(DirName);
                    Console.WriteLine("Creating directory: " + DirName);
                }

                // create a filestream to spit out the file
                FileStream fs = new FileStream(DirName + "/" + LeafName, FileMode.Create, FileAccess.Write);
                BinaryWriter writer = new BinaryWriter(fs);

                int bufferSize = 1024;
                long startIndex = 0;
                long retval = 0;
                byte[] outByte = new byte[bufferSize];

                // grab the file out of the db
                do
                {
                    retval = reader.GetBytes(4, startIndex, outByte, 0, bufferSize);
                    startIndex += bufferSize;
                    writer.Write(outByte, 0, (int)retval);
                    writer.Flush();
                } while (retval == bufferSize);

                // finish writing the file
                writer.Close();
                fs.Close();

                Console.WriteLine("Finished writing file: " + LeafName);
            }

            // close the DB connection and whatnots
            reader.Close();
            con.Close();
        }
    }
}
于 2012-05-08T23:51:24.647 回答
1

您可以尝试使用命令 stsadm.exe -o addcontentdb -url -databasename 在新的共享点环境和 webapp 中附加数据库。这种方式也用于将数据库从 sharepoint 2007 迁移到 2010 Farms。然后你应该在 webapp 的 url 中看到内容

于 2012-05-08T13:26:14.507 回答