2012-05-08 6 views
0

私はSharepointのデータベース(WSS_Content)を持っていますが、共有ポイントはインストールされておらず、そのデータが必要です。 データを取得するソリューションは何ですか? バイナリ配列からデータにファイル/リンク/サイトのデータを抽出するコンバータをコーディングする必要がありますか?これは簡単な方法ですか? フレッシュな共有ポイントをインストールしてこのデータベースを使用できますか?Sharepoint data retrieval

+0

どのようなデータが必要ですか、それで何をしていますか?サイトから文書を抽出するだけであれば、それはかなり簡単です。 –

+0

私はこのデータベースにいくつかのdoc、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

Nigelありがとうございます。それはまさに私が探していたものです。 – Saber

1

stsadm.exe -o addcontentdb -url -databasenameコマンドを使用して、新しいsharepoint環境とwebappにデータベースをアタッチできます。この方法は、SharePoint 2007から2010ファームにもデータベースを移行するために使用されます。その後、あなたはwebappのURLにコンテンツを表示する必要があります

+0

解決に感謝します。しかし、単にファイルを抽出する方が簡単でした。 – Saber

関連する問題