Sharepoint数据检索

时间:2012-05-08 09:35:22

标签: sharepoint

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

2 个答案:

答案 0 :(得分: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();
        }
    }
}

答案 1 :(得分:1)

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