2009-04-22 4 views
2

이전 문서 관리 시스템에서 SharePoint (MOSS 2007)로 많은 수의 문서를 이동하려고합니다. 원본 시스템은 이진 데이터를 SQL 서버 데이터베이스의 이미지 필드에 저장했습니다.SharePoint 문서에 데이터베이스 Blob 작성 Libaray

제 생각에는 프로그래밍 방식으로 여러 문서 라이브러리를 만들어 이러한 문서를 그룹화하는 것입니다. 그런 다음 이진 데이터를 파일 스트림으로 읽은 다음 해당 스트림을 사용하여 SharePoint에 파일을 업로드 할 계획입니다.

누구나 비슷한 일을 했습니까? 제가 작업하고있는 것보다 나은 접근법이 있습니까? 또한 바이너리 데이터베이스 필드에서 읽고 SharePoint 문서 라이브러리에 쓰는 예제가 있다면 감사하게 생각합니다. 감사.

답변

4

바이트 배열에서 프로그래밍 방식으로 문서를 쉽게 만들 수 있습니다. 빌드 할 수있는 코드 스 니펫이 있습니다.

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

답장을 보내 주셔서 감사합니다. 나는 그것을 사용할 것이다. –

관련 문제