2007-06-19

SPListItem and the CopyTo method

Yes, I've struggled with identifying the format of the destination url when trying to copy a publishing page from one Pages list to another using the SPListItem.CopyTo method. Again, Reflector came to my rescue. Reflector showed that the Url must contain a page name as well - NOT only the path to the list. If the page doesn't exist it will be created.

Wrong url: http://myserver/site/pages
Correct url: http://myserver/site/pages/thepagename.aspx

Then it works as it should.

Knowing how the publishing process is in SharePoint it really shouldnæt be a surprise, but sometimes the ... brain cells ... seems to be a bit "off line" :-)

3 comments:

Lubna said...

I have several inquiries regarding the copyTo method. Firstly, the copyTo method fails if the destination document library is empty. Once the document library is not empty the method works properly. Also, I would like to know the destination URL format if I am copying a custom list item.

chris said...

Good morning,

I am having an issue with the ListItem.CopyTo method. I wish to copy calendar items from calendar to another on a different site.However I get this error:
"Source item cannot be found. Verify that the item exists and that you have permission to read it."
Any ideas will be greatly appreciated.

Thank you
Regards
Chris

Rtr. Pankaj Bajpai said...

SPListItem.CopyTo(destinationUrl) method doesn't work with custom lists, instead you get the exception: "Source item cannot be found. Verify that the item exists and that you have permission to read it. You can check This Post which has code for copying items from one list to another