Mar 13

Sharepoint Database Exporter

Hi,

Some months ago I was experimenting with Windows Sharepoint Services and found out that my machine was not powerfull enough to run Windows 2003, SQL Server and Sharepoint at a decent speed. I had data in Sharepoint I wanted to keep so I did an SQL Server backup of the database. I tought that I would re-setup everything easily after a machine upgrade… I was wrong! I never succeeded to restore the database backup in a running Sharepoint environment (I learned the hard way that I should have used WSS backup utilities instead of relying only on a database backup).

From that moment I decided to explore how Microsoft stores its data within Sharepoint. I found out about Docs and UserData tables and I thought I could develop a little tool to extract my data. In the mean time I discovered the Sharepoint Database Explorer from James Edelen. I was happy that I would’nt have to code it myself :)… The tool is nice, but it didn’t allow me to export custom lists and metadata…

As a learning experience, I decided to build an exporter program. It happens that I find it usefull in a couple of situations… So I decided to share in case anybody would have the same needs than I had! :)

***** Updated (2008-02-21) *****

Features (v1.1.0.1):

  • It is possible to preview the pending version (checked-out and saved, but not yet checked-in) of a file.
    (on both: WSS 2.0 and WSS 3.0) (see this screenshot)
  • Bug fix regarding the extraction of document librarie items when files are checked-out.

Features (v1.1.0.0):

  • Connects to either Sharepoint 2003 or Sharepoint 2007 database structure (automatic detection).
  • It is possible to preview the version history of a file and to export individually a previous version of a file.

Features (v1.0.0.1):

  • Connects to Sharepoint 2003 databases directly
  • Does not rely on a working Sharepoint environment… it only connects to the database
  • You can preview the list contents (see screenshots)
  • It is possible to export individual files from the preview window.
  • You can export custom list attachments and document library files
  • You can export metadata

Metadata is exported in an xml file. For attachments, you have the choice to export them in a folder or to embed them in the xml.

Known issues:

  • When a list is not customized (kept as-is — no additional fields added), Microsoft does not store the column mapping (Sharepoint field name mapping to SQL Server column name). They probably store them in a resource file so its faster to retrieve than querying the database. For us, that means we have to hardcode the mapping for each list type (Custom List, Contact List, Discussion List, Calendar, etc.). For this reason, some list types may not export well.

Screenshots:

Download (Latest Version):

Add-On:

Download (Previous Versions):

Final Notes:
This work is done on my free time, but I encourage to post bugs and feature requests so I can take a look when I’ll have time.

Also if you made your own modifications, feel free to post them back so I can integrate them, of course giving you the credits for what you’ve done…

48 Comments so far

  1. Pascal May 8th, 2007 9:04 am

    Version 1.0.0.1 is now available. It contains a fix of a bug that was giving an error while exporting document libraries that contained sub-folders.

    My bad… I wanted to make to code cleaner before posting the first version to the site and I introduced a regression bug :(.

    A big thank you to Merijn Boom for reporting the bug and suggesting a fix.

    Pascal.

  2. Peter May 28th, 2007 5:36 am

    I finded a problem with export attachements from lists in this version (1.0.0.1). When I try save attachement from list I have error:

    System.Data.SqlClient.SqlException: Invalid column name ‘Content’. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    at System.Data.SqlClient.SqlCommand.ExecuteScalar()
    at Sharepoint2003.DBExporter.Data.DatabaseConnector.ExecuteScalar(string statement)
    at Sharepoint2003.DBExporter.SP.SPDatabase.GetFileContent(StringdocumentId)
    at Sharepoint2003.DBExporter.UI.ExplorerForm.PreviewFileListSaveAsMenuItem_Click(Object sender, EventArgse)

  3. Pascal May 30th, 2007 1:13 pm

    This tool is built for Sharepoint 2003.

    This is the typical error when trying to connect to a Sharepoint 2007 database using this tool because Microsoft has changed its database structure.

    If you’re really using Sharepoint 2003, feel free to write back.

    Pascal.

  4. Pascal June 12th, 2007 11:11 am

    I am currently working on a modified version for WSS 3.0. It is not ready to be published on this site yet. It currently works only for document libraries. But if any one is an urgent need, just drop me a message and I could send it by e-mail.

    You can expect to see it appear on my blog in the coming weeks, depending on how much interest I receive. It’s summer here and the sun is shining so I’m much more motivated to ride my bike than to sit in front of the laptop… ;)

  5. Pascal July 16th, 2007 8:47 am

    I have been asked a couple of time to send the version for WSS 3.0. For now, the development is stalled because I don’t have much time. All I have is a hacked version that is only able to export documents from document libraries (which is 99% of what is usually asked for).

    If you are in desperate needs of it, than here is the link of the Sharepoint 2007 Database Exporter ALPHA release:
    click here

    *** Edit: See main post — current release now supports both WSS 2.0 and WSS 3.0

    If it doesn’t work for you, or you need to export other types of lists, feel free to send me a comment and I’ll see what I can do.

    Note to Max: I tried to send it to you by e-mail, but I either mistype your address or you had a typo in it (it keeps bouncing). Unfortunately, I cannot verify because I’ve been to fast on the delete button :(.

    Pascal.

  6. Max July 16th, 2007 12:42 pm

    Pascal…

    Thanks for the link, I’m sure I probably typed something wrong.

    I tried the Alpha Exporter and it works great. No issues what so over. Pulled out about 800 documents totaling 500MB.

    You’d know better since you’ve worked on it, is it possible to extract the documents using the same folder structure that was on the site?

    If you have the source for this version, I can play with it in my spare time, but like you, there isn’t much of that.

    Great job on the program though. Saved our butts.

  7. Pascal July 16th, 2007 1:45 pm

    Well, I’m always happy to hear “success stories” about my little tool…

    I put the alpha version in a hurry and didn’t take the time to publish the source code yet. But I’ll do.

    For the directory structure, yes it could be possible to reproduce the same directory structure. I’ll put this in my todo list… It is still possible possible to “discover” the directory structure if you exported the metadata with the file. When exporting the metadata, the application generates an xml file containing the original location and its exported location. Based on the original location it would be possible to write a script to regenerate the directory tree…

  8. Nate July 17th, 2007 7:17 pm

    Thanks so much for posting the alpha. Saved our shop a large amount of recovery time after an unexpected db upgrade (caused by another app).

    Thanks for taking the time to work on this and for sharing!

  9. Andreas August 23rd, 2007 8:32 am

    The alpha works very well, did save us a lot of hastle after sharepoint services 3 simply did not do its job any more.

    Thanks a lot!

  10. Andy McNiece September 11th, 2007 9:52 am

    I would be very interest in the source for the WSS 3.0 binaries when they are available. I used the binaries with success.

  11. Blake Theiss September 21st, 2007 11:01 am

    Hey thanks for putting the time into this open source project… I used the 2007 alph version to grab the file… Really appreciate it…

  12. Kevin September 24th, 2007 11:50 am

    I urgently need to recover some deleted documents and associated metadata.

    Thanks to your fabulous tool, I now have an extract with attachments embedded in the xml file. Now for the silly question: How do I import this into SharePoint?

  13. Pascal September 24th, 2007 1:34 pm

    Andy:
    I’ll try to package it as soon as possible.

    Kevin:
    I was planning to build an importer that would use the sharepoint API to upload the files and metadata. Unfortunatly, I had no time for that. I built custom programs for specific situations for a customer but I can’t release the code since they are the owners.

    What is your version of Sharepoint? I’ll see what I can do.

    Pascal.

  14. Kevin September 24th, 2007 6:51 pm

    Pascal:
    Appreciate your help. Not sure which version number is more relevant to you so here’s both. WSS 11.0.7969.0 IIS 6.0.2.8117 - WSS+SP2+KB924881.

    Cheers
    Kevin.

  15. Pascal September 25th, 2007 8:19 am

    Ok that means you’re using WSS 2.0 (aka Sharepoint Services 2003). I was wondering if you were using the modified version for Sharepoint 2007.

    Pascal.

  16. Dave October 15th, 2007 5:56 am

    Hi,

    Do you have any guidelines / instructions / apps for importing data into Office Sharepoint 2007 (latest patched version) after it’s been exported using your tool?

    Great app, btw…

    Cheers,
    Dave

  17. Pascal October 15th, 2007 1:03 pm

    Hi Dave,

    It depends what you want to import… All of the feedback I received (with 1 exception) was from people exporting files from document libraries with no special metadata attached to them. That is easy to import using the new Sharepoint environment (ex: Explorer view of a document library).

    Do you have metadata to import? If so, I’m currently working on an importer. I plan to build the core with no graphical user interface so it can be available sooner.

    Pascal

  18. Pascal October 16th, 2007 8:22 am

    For those who were interested into having the Sharepoint 2007 Database Exporter source code (for Alpha 1), I finally had the time to package the code and place it on this site for download: click here for source code
    This alpha version is, in fact, the version for 2003 patched to work on SP2007. In the next release, the database exporter will be able to export both SP2003 and SP2007.

    Pascal.

  19. Tim November 12th, 2007 4:57 am

    This is a fantastic tool but just out of curiosity can you tweak it to allow export of specific pages? I’ve got a list on a production server where the EditForm.aspx and DispForm.aspx pages have suddenly stopped working if passed the “ID” parameter for the list item - if the parameter isn’t specified the pages load fine.

    Even Reset to Site Definition doesn’t work.

    My only hope seems to be to check these files as they are inside a backup…

  20. Tim November 13th, 2007 11:22 am

    Hi,

    This is a great utility!

    I don’t suppose you could possibly tweak it so that we can export pages and forms?

    I’m in desperate, desperate need of a utility that’ll pull the EditForm.aspx, DispForm.aspx and NewForm.aspx from a backup…

  21. Pascal November 13th, 2007 12:17 pm

    Tim: I think it is possible but I would need the version of Sharepoint you’re using.
    WSS 2 (2003)?
    WSS 3 (2007)?

    Pascal.

  22. ALKIM YILMAZ January 25th, 2008 11:32 am

    You are great. I was in a big trouble in the past 3 weeks and your tool worked perfect. I’ ve just changed my table name AllUserData to UserData on the database and there is no modification except that. Thank you so much.

  23. Grace January 30th, 2008 8:54 am

    the export notifies : 7 records retrieved, exporting, completed.
    The folder remains empty. what is the extenssion of the file, is it a hidden file, or something else? Thanks

  24. Pascal January 30th, 2008 11:56 am

    In the export tab you choose how the metadata is exported (not exported or exported as xml) and how attachments are exported (not exported, embedded within the xml of metadata or as a separate file). Depending on the options, you may have to select a file name or a folder location.

    In most situations, people exports document libraries and are not interested by the metadata. So the common options are:
    Metadata export format = “none”
    Attachments export format = “linked file”
    Export to: c:\temp\myfiles

    There is nothing exported has “hidden”. The extension used for attachments is the same as the original file stored in Sharepoint.

    Is this answering your question?

  25. B. Huard February 5th, 2008 5:57 pm

    Cool utility but I have a case it does not cover. I had a need to extract a document that was checked out and user did an undo check out by error. The document was saved in the DB backup but the tool only extracts the last saved document in a check-in state.

  26. Pascal February 6th, 2008 7:36 am

    Interesting case… I remember that I explored the possibility of displaying (in the preview tab) the history of each file and it wouldn’t be hard.

    I may end-up with something to help you in a day or two.

    Pascal.

  27. Pascal February 8th, 2008 11:22 pm

    Hi Bertrand,

    I just published a new version of the Sharepoint Database Exporter (v1.1.0.0) that may solve your problem.

    Pascal.

  28. Pascal February 21st, 2008 11:46 pm

    Bertrand:

    I finally built a test environment so I can add the requested feature. Version 1.1.0.1 does now support exporting checked-out file version on a WSS 2.0 and WSS 3.0 database version.

    Pascal.

  29. Tim February 26th, 2008 1:24 pm

    Pascal,

    Are you interested in adding command-line capabilities to this? It works well, actually I find it a bit faster and easier than the Edelen tool. I think directly accessing the db was a good move.

    For nightly exports, however, I’d like to automate it. In our company we are still using a giant network drive for all of our docs, so a few of us are trying out Sharepoint as an alternative but management is requiring us to still keep copies on our network drive. So an exporter that I can script to would be useful.

    Thanks for making this available,
    Tim

  30. Jennifer April 1st, 2008 9:19 am

    Thank you so much for posting this. I spent hours trying to restore a file and had tried the Edelen tool, but recieved errors. This was so easy and quick to use!

  31. Mark April 1st, 2008 5:31 pm

    Any updates on getting the folder structure preserved? I appreciate your continued efforts with this tool.

  32. Pascal April 2nd, 2008 7:37 am

    Hi Mark,

    This feature seems to have slip out of my hands last time I did an update… I guess I’ll find some time to implement it within the next week.

    Pascal.

  33. Pascal April 2nd, 2008 7:38 am

    Hi Tim

    I realized that I never answered your question…

    This tool is intended for last-chance data recovery. It is not meant to be part of a backup strategy because I cannot garanty 100% success result. The tool is extracting data from database that only Microsoft knows all the details.

    Based on its purpose, I don’t see much use of being converted to command-line. If you still wanna use it that way, it would be pretty easy to ask a developer to do it since the database access code is isolated from the user interface.

    Pascal.

  34. Martn Hespe April 16th, 2008 7:34 am

    Hi Pascal,

    I was experimenting with your excellent tool. I have a MOSS 2007 DB that contains elements from a SPS 2003 migration. I think I only can view elements with your application that were loded to the WSS Content DB after the migration. Or at least were openend and saved after the migration. Is there a way to also get access to the “hidden” data? For example I can see/extract about 200 files (40 MB) but there must be data over 1.4 GB…

    Thanks for answering!

    Best regards,

    Martin

  35. Pascal May 11th, 2008 7:42 am

    Hi,

    I never experienced this problem but I never tried for a database upgraded from SPS 2003 to MOSS 2007. Also, this tool was developed for WSS sites, were you trying to export portal data? (ex: data stored within areas)

    Pascal.

  36. Patrick June 10th, 2008 11:25 am

    I appreciate your efforts as well, but would be interested in some method like Tim indicated above of somehow automating an extract. We too need to have the documents pulled from the database for users. If your tool can’t accomplish this does anyone know of a solution for having this done nightly?

  37. Pascal June 12th, 2008 9:23 am

    Hi,

    This tool is not intended to be used on a working environment since it is a “last resort” recovery tool. If Microsoft changes its internal structure it will stop working.

    I found a tool made by krichie (http://blog.krichie.com) that is able to import/export a document library from the command line. I didn’t check the source code and didn’t test it yet but I’m pretty sure it should answer your needs.

    krichie published the application with the source code here:
    http://www.codeplex.com/SPIEFolder

    Pascal.

  38. Pascal June 12th, 2008 9:31 am

    As a side note, I will adapt my exporter to respect the original directory structure soon (as asked by Max before).

    When completed, the SPIEFolder tool from krichie (see previous comment) should allow to re-import documents into libraries of a working environment. That will greatly help recovering files.

    Pascal.

  39. Gareth June 16th, 2008 4:42 am

    Pascal,
    Awesome tool. Top marks. I’m current completely restoring a SharePoint 3.0 site as the stsadmin tool was not clear that I had to backup each top level site (I was converting from Windows Internal Database to SQL 2005)

    So, I was wondering - do you have any scripts or programs that can easily convert the XML code of the custom lists into a Excel Spreadsheet? I just wanted to check with you first before writing my own.

    Thanks in advance;
    Gareth

  40. Pascal June 16th, 2008 9:57 am

    Hi Gareth,

    If you use Microsoft Excel 2007 (and probably Excel 2003 will also work), you just have to open the xml file into Excel. If you have an older version, the easiest method is to convert the xml into an HTML Table or CSV file.

    I Added an “Add-on” section into this post with a link to an XSLT file that perform this transformation.

    Pascal.

  41. Gareth June 16th, 2008 2:54 pm

    Pascal,

    Oh ok couldnt be any easier - thanks alot for that - i’m running 2007 so it shouldnt be any issues. I wasnt looking at the problem from a simple enough approach ;)

    Thanks again,
    Gareth

  42. Gareth June 16th, 2008 10:38 pm

    Sorry, one last question although I think I already know the answer to this: Is there any way of preserving the Custom Views on the lists and/or any calculated fields?

    Thanks
    Gareth

  43. Pascal June 17th, 2008 9:26 am

    As you probably expected, currently there is no way to export the view definitions and formulas of calculated fields.

    Pascal.

  44. Gareth June 17th, 2008 2:45 pm

    Thanks for that - I suspected as much. Irrespective your tool just saved me alot of trouble. Thanks a LOT.

    Gareth

  45. Sudha June 18th, 2008 4:22 am

    Hi,

    Have worked on developing the webparts in sharepoint 2003 and .net1.0?
    I have certain clarifications needed on this ..if u can help me it wud be gr8.

    Sudha.

  46. Scotch July 10th, 2008 1:16 pm

    Thank you. You saved my life.. ;)

  47. Chris August 10th, 2008 3:35 pm

    Thanks for this, but I was hoping it could recover a CSS file in the Style Library. It exports only a listing of the files in the style library. Can you help?

    Thanks

  48. Pascal August 11th, 2008 2:53 pm

    You can choose to export a listing (meta data), the files (attachments) or both.

    In the export tab, choose:

    • Metadata export format: “XML”
      filename: [path to your xml file]
    • Attachments export format: “Linked file”
      Export to: [name of folder to export files to]

    Since you only want to recover a single file, you can “browse” to that file (in the Preview tab) and right-click on it to “save as” locally.
    (see this screenshot)

    Tell me if you succeed or if you still cannot recover your file.

    Pascal.

Leave a comment