Skip to content

Importing/Exporting SharePoint Document Libraries to/from the File System

February 21, 2007

Like my previous post, Purging a SharePoint list of all items and folders, here is another quick peice of code that will allow you to either Import a file system folder (And all files and subfolders) into a SharePoint Document Library, and also export a SharePoint Document Library to the file system. 

I had a SPExportWebFiles tool in the old Utility Suite that did the exporting, and an Import feature in SPSiteBuilder.  I’ve been waiting to find the time or opportunity to provide both a sample/tool that provided both import and export, and ran into that need today :) So, I thought I’d share.

The code contained in this file: SPIEFolder.txt, contains sample code to do just that, and create the nested folders as necassary to match the target location.

This code should work with either WSS 2.0/SPS2003 or WSS 3.0/MOSS 2007 without change. (I’ve only tested on WSS 3.0/MOSS btw at this time)

(Update 03-06-2007: See this link as this SPIEFolder is now published at http://www.codeplex.com/SPIEFolder )

(Update 06-02-2011: See this link SPIEFolder 1.0 removed and SPIEFolder for SharePoint 2010 is now published at http://blog.krichie.com/my-sharepoint-tools/#spiefolder)

So, got a folder you want to import into a SharePoint Document Library and you want to replicate the folder heirarchy and contents?  Or, want to export a SharePoint Document Library and replicate the folder heirarchy and contents on the file system?  This could help!

Hopefully this weekend, I’ll have some time to provide compiled versions, build scripts, and documentation like SPLSBackup for both this and the List Purging code as noted in my previous post.  But I doubt very seriously that the document will be as extensive as SPLSBackup :), as I don’t see a big need for that :).

HTH

Keith Richie

About these ads
35 Comments leave one →
  1. February 21, 2007 1:17 pm

    Hi ,
    Sorry this comment has nothing to do with your post. I am new to Sharepoint and I am having a lil problem with a webpart on SP07.
    I have used a Page Viewer Webpart to display a classic ASP Page. I would like to change the behaviour of this WebPart when ‘Edit’ is clicked and ‘Modify shared webpart’ is selected. I would like it to display another ASP Page. Is this possible? Or else is it possible to add another option onto the drop down that comes when clicking on ‘Edit’ of the webpart?
    Scratching my head.

  2. February 21, 2007 9:28 pm

    Unfortunately, that’s not my area of expertise at this time. You might want to post your question to the design and customization or development and programming newsgroup at http://www.microsoft.com/sharepoint/community.mspx

  3. Chris Fields permalink
    February 28, 2007 12:30 am

    Hi Keith. Yes, we would really like build scripts or compiled versions of this tool! Keep on coding.

  4. February 28, 2007 4:32 am

    Hey Chris :) I didn’t find the time last weekend obviously :) But I’ll see if I can’t knock it out over the next couple of days

  5. March 12, 2007 6:31 pm

    Hi Keith
    I am a fellow sharepoint and was wondering if you would be interested in joing SharePoint Knowledge Network on Feedburner Network.

    http://networks.feedburner.com/just-sharepoint

    Just use contact form on my blog if you are keen.
    Cheers!
    Alpesh

  6. Stuart permalink
    September 14, 2007 11:54 pm

    Hi Keith,

    Here’s what I want to do. I want to populate a document library on my Sharepoint site. The DL will have a lot of metadata such as author_name, abstract, etc. I then want to export the DL from my site and import the DL into another site. Will the meta data be preserved on export and import?

    Also, does the import process overwrite or append any existing document library of the same name? I would like to load the documents iteratively, in other words, load 100 docs per week at my office and take them over to the other sharepoint site? Would the import process automatically overwrite the existing DL at the other sharepoint site every time I did an import?

    Thank You,
    -Stuart

  7. Stuart permalink
    September 14, 2007 11:59 pm

    I should add that my site and the ‘other’ are physically separate and one of the sites does not have internet access.

  8. September 16, 2007 1:03 am

    Hi Keith,

    I´m trying to use SPIEF with MOSS 2007, to export some documents to a folder.

    SPIEFolder.exe http://servidor:8000 “hospital/central/Pruebas Primer Version” C:\admin\resplado export

    And I,m getting this error message: “El valor no está dentro del intervalo esperado” (Value not in the expected interval)

    Thanks in Advance,

    Jesus

  9. Keith Richie permalink
    September 19, 2007 8:36 am

    Jesus,

    from looking at your syntax, I’m assuming that “Pruebas Primer Version” is the actual name of your document library and “http://servidor:8000/hospital/central” is truly the name of your site, if so use this syntax

    http://servidor:8000/hospital/central “Pruebas Primer Version” C:\admin\resplado export

    Stuart

    Metadata is not preserved, and the import “Should” just iimport your new docs to the existing document library. It tries to “Add” the new folder to match the file system, and looking at the code, I could see where it would probably fail trying to add a subfolder that already exists. I can see a way for it to just check to see if that subfolder already exists, then select it for import, but don’t know when I’d be able to get to it.

    I’m supposed to re-publishing SPSIteManager soon, but can’t seem to find the time to get that done right now :)

  10. September 20, 2007 5:57 am

    would this tool enable me to take a document library from one sharepoint site on an intranet and move it and all of its contents to a completely different teamsite on the same intranet? i know what i want to do, but i cant translate anything on the microsoft help site and my sharepoint manipulation skills are relatively limited.
    thanks!

  11. November 21, 2007 8:03 pm

    I just ran across this and was wondering:

    How does it handle invalid WSS 3.0/2.0 characters in filenames? Generally on a file server people use everything they can think of to name a file. Will thisdo a rename and weed out the erroneous characters before an upload.

    If not would you mind if I changed your code to make i work for such a situation?

  12. November 21, 2007 10:00 pm

    Hey Stephen, I don’t believe I put in any special handling for that, but sure if you change the code to work for you, I’d love to integrate the changes into the tool

  13. Matt permalink
    January 19, 2008 3:04 am

    Hey Keith,

    Just found this online and it solved a major headache for me and works flawlessly! Thanks for sharing your excellent tool with the rest of us!

    Matt

  14. January 19, 2008 3:57 am

    Your welcome Matt!

  15. Trevor permalink
    April 17, 2008 11:00 pm

    Using your SPIEFolder tool to do extracts and it’s saving me tons of time. I do seem to have an issue on one my environments where the tool keeps saying “The server instance specified was not found. Please specify the server’s address and port.” I can’t seem to get around this problem — on a Project/Sharepoint server 2003 (WSS2).

    This may be helpful for others also. I wanted to generate a list of all sites and their libraries for export using SPIEFolder tool. I was looking at doing this manually but got some help on the SQL side of things and came up with this query to produce the list for me. Save me days of work.


    SELECT DISTINCT 'http:///' + W.FullUrl AS URL, L.tp_Title, L.tp_BaseType, W.FullUrl
    FROM dbo.Lists L INNER JOIN
    dbo.Webs W ON W.Id = L.tp_WebId
    WHERE (L.tp_BaseType = '1') AND (L.tp_Title NOT LIKE '%Gallery%') OR (L.tp_BaseType = '5')

  16. Trevor permalink
    April 17, 2008 11:01 pm

    Repost: Comment scrubbed some code

    SELECT DISTINCT ‘http://{domain name}/’ + W.FullUrl AS URL, L.tp_Title, L.tp_BaseType, W.FullUrl
    FROM dbo.Lists L INNER JOIN
    dbo.Webs W ON W.Id = L.tp_WebId
    WHERE (L.tp_BaseType = ‘1’) AND (L.tp_Title NOT LIKE ‘%Gallery%’) OR (L.tp_BaseType = ‘5’)

  17. April 18, 2008 12:18 am

    Trevor, that’s fine if you run it on a system that isn’t a live production copy of the database, just note that direct queries against live content databases is Very unsupported :)

  18. Bill Walton permalink
    May 20, 2008 1:09 am

    Keith,

    I’m brand new to Sharepoint from an api perspective and have been given an assignment that requires writing files (from a Windows network file share) to specific locations in a Sharepoint 2007 server. We’re using Ruby and Ruby on Rails as our web development environment. I’ve figured out how to read files from Sharepoint, but am having real troubles getting my arms around how to do the writes to Sharepoint. I’m thinking that maybe, rather than ‘pushing’ the files into Sharepoint, there’s a ‘pull’ strategy available where Sharepoint gets set up to monitor a (set of) directory(ies) and fetches them. Your thoughts?

    Thanks,
    Bill

  19. May 21, 2008 12:23 am

    Hey Bill,

    Take a look at the code in the tool related to this posting, specifically at the ImportFilesToFolder() method.

    Basically, you read the contents of the file into a buffer, then add it to the appropriate list/folder etc.

    Funny you ask this question, because I’m actually starting a project that will monitor a folder and do a synch as you mention via a pull strategy.

    Sure there are other applicaitons out there for this type of work, but I want to do it as an excercise and actually extend the idea behind SPIEFolder.

  20. January 15, 2009 12:21 am

    Is that URL stamped as a host header for the web application?

  21. doktorhallam permalink
    June 25, 2009 6:36 pm

    thanks for the tool. couple quickies, first off, forgive my ignorance. not sure how to construct the files to work. am i assuming correctly that i modify the appropriate .cmd file with my info and execute that and let it call the .exe file? also, if i were to make mods to the source, how to recompile? and include the program.cs and assemblyinfo.cs files? also, looking forward to a sync tool if you are still working on and have the time.
    Thanks!

    • doktorhallam permalink
      June 25, 2009 6:57 pm

      ok, thats what documentation os for. forgive me once again. thanks, great tool. will be looking to modify to maintain some issues, such as meta data, etc. also, would be very interested in seeing some maintenance of versioning and possibly even a way for the check out/in functioning, but not sure how to implement, and guessing would be rather extensive.
      but thanks again!

  22. Tim permalink
    October 9, 2009 12:29 am

    I am getting the following message when I try to export

    Cannot open database “WSS_Content_75c297d01091435fbbd57b63dadd39cb” requested by
    the login. The login failed.
    Login failed for user ‘domain name\username

  23. Paul D permalink
    January 20, 2010 3:25 am

    Is it possible to get a version of this that is designed to upload a single file instead of requiring it to start as a dir structure?

  24. Israel Gonzalez permalink
    April 29, 2010 9:59 pm

    I see that this tool is not exporting all the metadata for the file. Is there a way to fix that so all metadata is exported out.

    • April 30, 2010 7:33 pm

      Israel,
      It currently does not export ANY metadata, and there are no plans to do so.

  25. Rick Hekkenberg permalink
    May 12, 2011 2:33 am

    Hello Keith,

    I think your tool is brilliant, it has been working very well for us to use as a tool to backup student documents.

    We have run into a slight problem and hope you can give us some pointers. Exporting documents work all but .dwt files (Dreamweaver Template):

    Exporting file Template.dwt to x:\test\Personal Documents\WEBSITE BACKUP\Weba
    site\Web work 2011\Templates\Template.dwt
    Could not access server.

    Rick
    Thanks,

  26. Simon permalink
    August 10, 2011 6:05 pm

    Hi Keith,

    Trying to import a folder to Sharepoint 2007 I’m getting this error, your kind advice would be most appreciated:
    Could not load file or assembly ‘Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ or one of its dependencies. The system cannot find the file specified.

    • August 11, 2011 6:24 pm

      Simon, that’s because you’re trying to run a tool built for SharePoint 2010 on a SharePoint 2007 system. I have a 2007 version of SPIEFolder 2.0 in the works, and will post to my tools page when it’s ready.

  27. Simon permalink
    August 11, 2011 6:55 pm

    [FX: BLUSH] I was assuming there was backwards compatability. Thanks for clarifying!

    • Satish permalink
      August 18, 2011 3:00 am

      Hey Keith, Heard a lot of great things about your tool on the internet. I would like to run your tool on my 2007 env. Anyway i can get ver 1.0, until you have 2.0 ready for 2007?

      Thanks
      Satish

Trackbacks

  1. Quick Links Krichie Edition » Sharepoint BUZZ - Blogging the Best of SharePoint 2007 (MOSS)
  2. SPIEFolder on CodePlex - Importing/Exporting SharePoint Document Libraries « Krichie - That SharePoint Guy
  3. SharePoint Buzz

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 1,623 other followers

%d bloggers like this: