首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sharepoint数据检索

Sharepoint数据检索
EN

Stack Overflow用户
提问于 2012-05-08 17:35:22
回答 2查看 228关注 0票数 0

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-05-09 07:51:25

我发现了一个我不久前用过的旧应用程序,它可以从内容数据库中提取所有文档。它在任何方面都不是选择性的,它只是抓住那里的一切。然后,您可以选择输出以获得所需的内容。

我相信原始代码来自其他人(我记不起哪里不能信任他们)。我只是稍微黑了一下。尽管试一试吧。

它只是直接访问数据库,所以您只需要将其装载到SQL Server中即可。不需要SharePoint服务器。

代码语言:javascript
复制
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();
        }
    }
}
票数 2
EN

Stack Overflow用户

发布于 2012-05-08 21:26:15

您可以尝试使用命令stsadm.exe -o addcontentdb -url -databasename在新的sharepoint环境和webapp中附加数据库。此方法也可用于将数据库从sharepoint 2007迁移到2010场。然后,您应该会看到webapp的url中的内容。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10496098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档