将数据库Blob写入SharePoint文档库

将数据库Blob写入SharePoint文档库,sharepoint,Sharepoint,我正在将大量文档从较旧的文档管理系统移动到SharePoint(MOSS 2007)。原始系统将文档作为二进制数据存储在SQL server数据库的图像字段中 我的想法是以编程方式创建多个文档库来对这些文档进行分组。然后,我计划将二进制数据读取到文件流,然后使用该流将文件上载到SharePoint 有人做过类似的事情吗?有没有比我正在研究的更好的方法?此外,如果有人有任何从二进制数据库字段读取和写入SharePoint文档库的示例,我将不胜感激。谢谢 您可以轻松地从字节数组以编程方式创建文档。

我正在将大量文档从较旧的文档管理系统移动到SharePoint(MOSS 2007)。原始系统将文档作为二进制数据存储在SQL server数据库的图像字段中

我的想法是以编程方式创建多个文档库来对这些文档进行分组。然后,我计划将二进制数据读取到文件流,然后使用该流将文件上载到SharePoint


有人做过类似的事情吗?有没有比我正在研究的更好的方法?此外,如果有人有任何从二进制数据库字段读取和写入SharePoint文档库的示例,我将不胜感激。谢谢

您可以轻松地从字节数组以编程方式创建文档。 这里有一些代码片段,您可以在此基础上进行构建

// 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();
  }
}

谢谢你的回复。我会使用它。