copyitem

Mar 29, 2011 at 3:26 PM

operation: "CopyIntoItemsLocal"

SourceUrl: http://host1.com/Shared%20Documents/test.docx

DestinationUrls: [http://server2.com/Shared%20Documents/test.docx]

Is this possible? I am able to use this operation for http://host1.com/sites3/testlibary/test.docx But for other url, it give me access deined.

Coordinator
Mar 29, 2011 at 3:32 PM

Note the definition for the operation on the MSDN SDK page:

"Copies a document from one location on a server running Windows SharePoint Services to another location on the same server."

M.

Mar 29, 2011 at 4:16 PM

Thanks for reply.

Sorry for the confusion.

host1.com and server1.com are 2 webapplications hosted on same server with different host headers.

Thank you

Anil

 

Mar 29, 2011 at 8:10 PM

Even if did work across servers, you still have the cross-domain javascript issue that would block the action as well.

May 2, 2011 at 11:15 PM

Works like a charm for me, quickest way to copy documents I have tried. Copies 100 documents in less than 30 seconds. Works cross domain between webapps if it's the same farm. I'm including the following in a CEWP on the form page (like Allitems.aspx I know it's not the prettiest code ever made but it works)

This lists the documents in the folder and lets you copy them either one by one or all together to a Document Library/Folder

 

 

<script src="http://yourScriptLibrary/jquery-1.4.2.min.js"></script>
<script src="http://yourScriptLibrary/jquery.SPServices-0.5.5.min.js"></script>


<script>
var webDomain='http://yourSourceDomain(NotSite).com';
var libraryName='Pages';

function copyItem(source, destination, inputObject) {
 	$(inputObject).hide();
	$(inputObject).after('<img src="/_layouts/images/Kpiprogressbar.gif"/>');
 	$().SPServices({
		operation: "CopyIntoItemsLocal",
		SourceUrl: webDomain+''+source,
		DestinationUrls: [$('#destination').val()+"/"+destination], 
		completefunc: function(xData, Status) {
			$(inputObject).next().remove();
			if($(xData.responseXML).find("CopyResult").attr("ErrorCode")=='Success'){	
				$(inputObject).after('<p>'+$(xData.responseXML).find("CopyResult").attr("ErrorCode")+'</p>');
			}
			else{
				$(inputObject).after('<p>'+$(xData.responseXML).find("CopyResult").attr("ErrorCode")+': '+$(xData.responseXML).find("CopyResult").attr("ErrorMessage")+'</p>');
			}
		}
	});
}
function getItemsToCopy(copyAll){
	var rootFolder=$().SPServices.SPGetQueryString()['RootFolder'];
	if(rootFolder===undefined){
		rootFolder=window.location.href.substring(0, window.location.href.indexOf('Forms'));
	}
	rootFolder=unescape(rootFolder.replace(/\+/g, " "));
	$("#site").val(rootFolder.substring(0, rootFolder.indexOf(libraryName)));
	$("#folder").val(rootFolder.substring(rootFolder.indexOf(libraryName)+libraryName.length+1));

	$().SPServices({
		webURL: $("#site").val(),
		operation: "GetListItems",
		listName: libraryName,
		CAMLViewFields: '<ViewFields><FieldRef Name="Title"/><FieldRef Name="DocIcon"/><FieldRef Name="ID"/><FieldRef Name="DocIcon"/><FieldRef Name="GUID"/><FieldRef Name="ServerUrl"/><FieldRef Name="LinkFilename"/></ViewFields>',
		CAMLQuery: '<Query><OrderBy><FieldRef Name="Title" /></OrderBy><Where><Neq><FieldRef Name="ContentType" /><Value Type="Choice">Folder</Value></Neq></Where></Query>',  // query 
		CAMLRowLimit: 1000,
		CAMLQueryOptions: '<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><Folder>Pages/'+$("#folder").val()+'</Folder></QueryOptions>',  // queryOptions
		completefunc: function (xData, Status) {
			$(xData.responseXML).find("[nodeName=z:row]").each(function() {
				var ServerUrl = $(this).attr('ows_ServerUrl').replace(/\'/g,"%27");
				var LinkFilename = $(this).attr('ows_LinkFilename').replace(/\'/g,"%27");
				if(copyAll=='yes'){
					copyItem(ServerUrl, LinkFilename, $("#copyButton"+$(this).attr('ows_ID')));
				}
				else{
					$("#output").append('<tr><td><a href="'+$(this).attr('ows_ServerUrl')+'">'+$(this).attr('ows_LinkFilename')+'</a></td><td><input id="copyButton'+$(this).attr('ows_ID')+'" type="button" value="Copy" onclick="copyItem(\''+ServerUrl+'\', \''+LinkFilename+'\', this)"/></td></tr>');
				}
				
					
			});			
		}
	});
}

$(document).ready(function() {
  	getItemsToCopy();
});
</script>
</head>
<body>
<table style="display:none"><tr><td>Site</td><td>Folder</td></tr>
<tr><td><input id="site" value=""/></td><td><input id="folder"/></td></tr></table>
<input type="button" value="Copy All To" onclick="getItemsToCopy('yes');"> <input size="40" value="http://YourDestinationSite.com/SiteName/DocLibName/Folder" id="destination"/>
<table id="output"></table>			
</body>