Add a document to a library

Feb 9, 2010 at 3:22 PM

Hello,

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,

Mark

Coordinator
Feb 9, 2010 at 3:48 PM

Mark:

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 http://spservices.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=40011 I haven't done any testing, so it's a bit of caveat emptor right now.

M.

Feb 9, 2010 at 5: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!

Coordinator
Feb 9, 2010 at 5: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.

M.

Feb 9, 2010 at 6: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;
		$().SPServices({
			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;
}
$(document).ready(PreSaveAction);
</script>
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 7: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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <soap:Body>
            <GetItemResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
               <GetItemResult>0</GetItemResult>
      
               <Fields>
                  <FieldInformation Type="Error" DisplayName="Content Type ID" InternalName="ContentTypeId" Id="" Value=""></FieldInformation>
      			<!-- Snip -->
                  <FieldInformation Type="Computed" DisplayName="Relink" InternalName="RepairDocument" Id="" Value="0"></FieldInformation>
               </Fields>
      
               <Stream>PGh0bWwgeG1sbnM6bX<!-- Snip -->L2JvZHk+DQo8L2h0bWw+</Stream>
            </GetItemResponse>
         </soap:Body>
      </soap:Envelope>
      
  • 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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <soap:Body>
            <soap:Fault>
               <faultcode>soap:Server</faultcode>
               <faultstring>Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</faultstring>
      
               <detail>
                  <errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Object reference not set to an instance of an object.</errorstring>
               </detail>
            </soap:Fault>
         </soap:Body>
      </soap:Envelope>
      
      

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.

Coordinator
Feb 11, 2010 at 3:04 AM

Mark:

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

M.

Nov 23, 2010 at 9:18 AM

Hello,

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.

Cheers,

Jonathan

 

 

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

Hi,

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

 

Regards,

Pallavi

Jan 18, 2013 at 8:20 AM

Solved !

Apr 29, 2013 at 3:01 PM
Hello,

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 9: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.