Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I dug up an old app I had a little while back that does a really basic extraction of all documents from a content database. It's not selective in any way, it just grabs whatever is there. You can then pick through the output to get what you needed.</p> <p>I believe the original code came from someone else (I can't remember where so can't credit them). I just hacked it a little bit. Feel free to give it a shot.</p> <p>It just accesses the database directly, so you just need it mounted in SQL Server. No SharePoint server required.</p> <pre><code>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(); } } }</code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload