This project has moved and is read-only. For the latest updates, please go here.

Add a document to a library

Feb 9, 2010 at 4:22 PM


First let me say what a wonderful experience I've had in the short time I've been using your library. It's a fantastic tool, and I really appreciate the effort and time that has gone into this.

I don't know if this is even possibly via normal soap calls to the services, never mind through your library, but I'm hoping to add a new document to a document library. Everything I've looked at doesn't seem to support this, but I thought I would ask before giving up on it.

Thanks so much for your hard work,


Feb 9, 2010 at 4:48 PM


I'm glad you are finding the library useful!

Where would the document be coming from?  Have you looked at the Copy Web Service's GetItem and CopyIntoItems operations?  I've just added them into the v0.5.1 alpha available here I haven't done any testing, so it's a bit of caveat emptor right now.


Feb 9, 2010 at 6:03 PM

You, sir, are a life saver!

I am copying a file from a remote server(same intranet), and this worked wonderfully.

In case anyone else needs it, I used the example documented in CopyIntoItems by LeSanglier, changed the URLs and the operation name to CopyIntoItems, and it worked beautifully!

Now to figure out for to embed a file stream into it without having to have a URL for the source file :)

Thanks again!

Feb 9, 2010 at 6:09 PM

Great! So you're one of my alpha testers for the CopyIntoItems operation. Thanks!

I *think* any URI ought to work with GetItem, but I'm not sure. That ought to include a file share, etc.  Let me know what you find out.


Feb 9, 2010 at 7:36 PM

So far I've tried a straight stream embed, and it worked just fine. As I'm running this on a seperate server, I base64 encoded a file and embed it in my code. It ends up looking like this:


<script language="javascript" type="text/javascript" src="jquery-1.4.1.js"></script>
<script language="javascript" type="text/javascript" src="jquery.SPServices-0.5.1ALPHA1.js"></script>
<script language="javascript" type="text/javascript" >
	function PreSaveAction() {
	var now = new Date;
			operation: "CopyIntoItems",
			webURL: "http://example2/",	
			async: false,
			SourceUrl: "http://example1/5646489186.html",
			Stream: "PGh0bWw+DQoJPGJvZHk+DQoJCWpxdWVyeS5TUFNlcnZpY2VzLTAuNS4xQUxQSEExLmpzIGlzIGZhbnRhc3RpYyENCgk8L2JvZHk+DQo8L2h0bWw+",
			DestinationUrls: ["http://example2/sharepoint/postProto/5646489186.html"],
			completefunc: function(xData, Status) {
					alert("Status=" + Status + " XML=" + xData.responseXML.xml);	
	return true;
The source URL is not a real file, and can be set to anything at all. If the stream is ignored, then it will do a lookup on the SourceUrl and try to pull that file. I'll post back about my attempte with GetItem
Feb 9, 2010 at 8:57 PM

So I did a little testing with GetItem, and found this: (I understand that if people know how the services work this is really redundant, but for someone like myself I find it useful, so I'm posting in case others are in my circumstance)

  • Calling the GetItem operation with only a URL as an argument to a file within a SP you should get something like:
    • <?xml version="1.0"?>
      <soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd="">
            <GetItemResponse xmlns="">
                  <FieldInformation Type="Error" DisplayName="Content Type ID" InternalName="ContentTypeId" Id="" Value=""></FieldInformation>
      			<!-- Snip -->
                  <FieldInformation Type="Computed" DisplayName="Relink" InternalName="RepairDocument" Id="" Value="0"></FieldInformation>
               <Stream>PGh0bWwgeG1sbnM6bX<!-- Snip -->L2JvZHk+DQo8L2h0bWw+</Stream>
  • When calling a windows network location as your Url(Like \\windows\network\example.pdf) or an external URL(Like http://exmaple1/example.pdf) you'll generate an error
    • <?xml version="1.0"?>
      <soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd="">
               <faultstring>Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</faultstring>
                  <errorstring xmlns="">Object reference not set to an instance of an object.</errorstring>

So i guess it's only for pulling from two different Sharepoint, and using the base64 data and the meta you could import it into another library with CopyIntoItems.

Feb 11, 2010 at 4:04 AM


Thanks for posting the results of your investigation.  It may well help others down the road.


Nov 23, 2010 at 10:18 AM


First, thanks for the library - I have been using it expensively on my current project.  Next,  I want to thank Mark [Greven], becuase your posts did "help others down the road".   Two things to add:

1)  it appears the order of the parameters in the call to $().SPServices when using CopyIntoItems is important. I was getting errors until I changed the order to match Mark's example above.

2)  I used a tiny silverlight control to let the user select the file to upload (in my case images) and do the conversion to binary64. Worked like a charm. 

Thanks again.





Jan 18, 2013 at 9:11 AM
Edited Jan 18, 2013 at 9:12 AM


I am using copyintoitems to copy document. However I need to assign the document properties also. What is the syntax to provide "Fields" information to SPservices - CopyintoItems operation? Please help its urgent




Jan 18, 2013 at 9:20 AM

Solved !

Apr 29, 2013 at 4:01 PM

I am trying to upload a file from local machine to Sharepoint's document library. I need to do this from client side. Can anyone please help.
Sep 13, 2013 at 10:04 PM
Can any one please guide me how to convert a string (XML, reasonably good size) to stream, to be passed to CopyIntoItems method. I am trying several methods, with no success. Any help would be really appreciated.