我正在将大量文档从较旧的文档管理系统迁移到SharePoint (MOSS2007)。原始系统将文档作为二进制数据存储在SQL server数据库的图像字段中。
我的想法是以编程方式创建多个文档库来对这些文档进行分组。然后,我计划将二进制数据读出到一个文件流中,然后使用该流将文件上传到SharePoint。
有没有人做过类似的事情?有没有比我正在做的更好的方法?此外,如果任何人有任何读取二进制数据库字段和写入SharePoint文档库的示例,我将不胜感激。谢谢。
发布于 2009-04-22 19:39:35
您可以轻松地从字节数组以编程方式创建文档。下面是一些代码片段,您可以在此基础上进行构建。
// If you have very large document, you might consider export the BLOBs to disk instead of in memory
string connstr = @”Data Source=.;Initial Catalog=AdventureWorks;Persist Security Info=True;User ID=sa;Password=sa”;
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(“SELECT * FROM [dbo].[ImageStore]“, conn);
DataSet ds= new DataSet();
da.Fill(ds);
byte[] blob = (byte[])ds.Tables[0].Rows[0]["imageContent"];
using (SPSite destinationSite = new SPSite("http://YourSite"))
{
using (SPWeb = destinationSite.OpenWeb("http://YourSite"))
{
SPList destinationDocuments = destinationWeb.Lists["Documents"];
string fileName = "mydoc.jpg";
string relativeDestinationUrl = destinationDocuments.RootFolder.Url + "/";
stringfileName += sourceItem.File.Name;
relativeDestinationUrl += fileName;
SPFile destinationFile = ((SPDocumentLibrary)destinationDocuments).RootFolder.Files.Add(relativeDestinationUrl, blob, true);
SPListItem item = destinationFile.Item;
item.UpdateOverwriteVersion();
}
}https://stackoverflow.com/questions/778504
复制相似问题