Importing folders to SharePoint

I’ve been working with Small Business Server 2008 recently and one of the tasks was to import an existing shared folder into SharePoint.

You would have thought that would be trivial, but it turns out it is not quite so. The normal suggestion is to open a SharePoint library in Explorer and do the import there. That’s actually not ideal. One problem is that, at least in our case, it does not work on the server though it does work on workstations. I suspect this is some arcane permission problem or feature; but doing this over the network is inefficient. Another issue is that Explorer is not smart about things like setting the date to that of the original, which can be annoying. A third problem is that some characters are allowed in document names on the file system, but not in SharePoint – such as  & { } and %. If your Explorer copy hits one of these the copy will fail.

I looked for a script-based solution, initially using PowerShell, but came across SPIEFolder instead. This is a simple C# application. Once I’d figured out that you have to run it from an elevated command prompt, it worked fine. However, it only imports into the top level of a SharePoint library. I added a target subfolder argument to SPIEFolder, and some name mangling to deal with illegal characters, and now it does what I want. I’ve not changed the default file date behaviour yet; but I think I can see how do do this if necessary: see for the code.