How do I upload a document to SharePoint with Java?

Aaron Digulla picture Aaron Digulla · Nov 24, 2008 · Viewed 42.1k times · Source

I'm creating some big files (DB exports) with Java and I need to put them somewhere on our SharePoint server. Right now, I'm doing this with IE but I'd like to automate this step, too.

I searched the web and I found some hints to use SOAP but I don't really see to the ground of all this, yet. Can someone provide me with some sample code or a recipe what I need to do?

Please note: the SharePoint server asks for NT domain authentication. I can't even login with Firefox :(

EDIT

  • How do I convert the scary URL in IE into a WebDAV path?
  • Is there a WebDAV "explorer" which I can use before I ruin the production system with my code? I tried "DAV Explorer 0.91" from http://www.davexplorer.org/ but that can't connect (probably because of NT domain auth).

Answer

dariom picture dariom · Nov 24, 2008

In addition to Sacha's suggestions, you can use the SharePoint SOAP web services. Each SharePoint site exposes a bunch of web services via the path http://<Site>/_vti_bin/.

In your case, you probably want the Lists web service (http://<Site>/_vti_bin/Lists.asmx). You can grab the WSDL from http://<Site>/_vti_bin/Lists.asmx?WSDL. The WSS 3.0 SDK has details on how to use the web service (you'll probably want to use the UpdateListItems and AddAttachment methods).

All that said, Sacha's first option (mapping a document library to a drive) is probably the easiest way assuming you can get around the NTLM issues.

If you're using Windows you can simply navigate to a UNC path for a document library. For example, if the browser URL for your document library is:

http://<Site>/Foo/BarDocs/Forms/AllItems.aspx

you can simply type the corresponding UNC path in the Windows Explorer address bar:

\\<Site>\Foo\BarDocs

and then drag and drop files to this location. If you'd like you can map this location to a drive letter using Windows Explorer or the SUBST.EXE command-line utility.