2012-05-08 47 views
0

我有一個Sharepoint的數據庫(WSS_Content),但沒有安裝sharepoint,我需要它的數據。 你有什麼解決方案來檢索數據? 我應該編碼一個轉換器從二進制數組中提取文件/鏈接/站點數據到數據還是有更簡單的方法? 我可以安裝全新的共享點並使用此數據庫嗎?Sharepoint數據檢索

+0

你需要什麼樣的數據,你會用它做什麼?如果你只是需要從網站提取文件,那很簡單。 –

+0

我有一些文檔,docx,jpg,odc,pdf,pptx,zip,rar文件到這個數據庫中。只是想提取文件。 – Saber

回答

2

我挖了一箇舊的應用程序,我有一段時間後,做了一個真正的基本提取內容數據庫中的所有文件。它沒有任何選擇性,只是抓住了那裏的一切。然後你可以選擇輸出來獲得你需要的東西。

我相信最初的代碼來自別人(我不記得在哪裏,所以不能稱爲他們)。我只是一點點入侵了它。隨意給它一個鏡頭。

它只是直接訪問數據庫,所以你只需要它掛載在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(); 
     } 
    } 
}
+0

謝謝奈傑爾。這正是我所期待的。 – Saber

1

您可以嘗試通過命令stsadm.exe -o addcontentdb -url -databasename將數據庫附加到新的sharepoint環境和webapp中。這種方式也用於將數據庫從SharePoint 2007遷移到2010 Farms。然後,你應該看到在webapp的網址內容

+0

感謝您的解決方案。但提取文件比較容易。 – Saber