'Usage Dim instance As SPListItem Dim destinationUrl As String instance.CopyTo(destinationUrl) 'Declaration Public Sub CopyTo ( _ destinationUrl As String _ )
A string that contains the URL of the destination to which to copy the item.
The destination URL must reside on the same server on which the code is running. This copy operation does not copy to URLs on remote servers.
Here is a possible exception you may recieve:
Microsoft.SharePoint.SPException: Source item cannot be found. Verify that the item exist and that you have permission to read it. at Microsoft.SharePoint.SPCopy.CopyIntoNewItem(SPListItem src, SPFolder targetFolder, String targetUrl) at Microsoft.SharePoint.SPCopy.CopyIntoItem(SPListItem src, String targetUrl) at Microsoft.SharePoint.SPListItem.CopyTo(String destinationUrl) at CopyMoveToParentFolder.Program.Main(String[] args)
Note: In MOSS 2007 it is not possible to copy/move an item from List/Folder/Folder/Item to List/Folder/Item in sitemanager (UI).
what is the possible resolution ?
Another possible Exception, because of malformed destinationUrl
Void CreateThis(System.String, Boolean, System.UriKind)System.UriFormatException: Invalid URI: The format of the URI could not be determined. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.Uri..ctor(String uriString) at Microsoft.SharePoint.SPCopy.EnsureValidUrl(String url) at Microsoft.SharePoint.SPCopy.GetItemForUrl(String url) at Microsoft.SharePoint.SPCopy.CopyIntoItem(SPListItem src, String targetUrl) at Microsoft.SharePoint.SPListItem.CopyTo(String destinationUrl)
destinationUrl has to be an absolute URL including the destination file name.
E.g. http://host/site/web/list/filename.aspx
InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()
Microsoft.SharePoint.SPCopy.CopyIntoItem(string srcUrl, SPListItem target, Hashtable props, byte[] stream, bool saveStream)
Microsoft.SharePoint.SPCopy.CopyIntoItem(SPListItem src, SPListItem target)Microsoft.SharePoint.SPCopy.CopyIntoItem(SPListItem src, string targetUrl)Microsoft.SharePoint.SPListItem.CopyTo(string destinationUrl)
OR
Microsoft.SharePoint.SPException occurred Message="Cannot lock file \"BPF WCD-F-0007.xml\". Either the file is in use or the Web server is temporarily busy." Source="Microsoft.SharePoint" ErrorCode=-2130247155 StackTrace: at Microsoft.SharePoint.Library.SPRequest.MoveUrl(String bstrUrl, String bstrWebRelOldUrl, String bstrWebRelNewUrl, Int32 grf) at Microsoft.SharePoint.SPFile.MoveCopyInternal(String strNewUrl, Int32 grf) at Microsoft.SharePoint.SPFile.CopyTo(String strNewUrl) at ChangeOrderProposal.CustomActivities.CopyDocumentsAndAttachmentsActivity.CopyDocument(SPFile document, SPList destinationList)
In case someone needs a bit light in using this method, here is example:
SPListItem itemToCopy; //original item to copy
This should be all that is needed to copy items using this method.