我有一个共享数据库(WSS_Content),但没有安装Sharepoint,我需要它的数据。您检索数据的解决方案是什么?我应该编写一个转换器来从二进制数组中提取文件/链接/站点数据,还是有更简单的方法?我是否可以安装全新的sharepoint并使用此数据库?
发布于 2012-05-09 07:51:25
我发现了一个我不久前用过的旧应用程序,它可以从内容数据库中提取所有文档。它在任何方面都不是选择性的,它只是抓住那里的一切。然后,您可以选择输出以获得所需的内容。
我相信原始代码来自其他人(我记不起哪里不能信任他们)。我只是稍微黑了一下。尽管试一试吧。
它只是直接访问数据库,所以您只需要将其装载到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-08 21:26:15
您可以尝试使用命令stsadm.exe -o addcontentdb -url -databasename在新的sharepoint环境和webapp中附加数据库。此方法也可用于将数据库从sharepoint 2007迁移到2010场。然后,您应该会看到webapp的url中的内容。
https://stackoverflow.com/questions/10496098
复制相似问题