Dailycode.info

Short solution for short problems

Unlink a list item from source item

When you use the Copy method, to copy a list item from one list to another, the item is linked automatically to the source item. This enables the user to go to the source item, even if we don't like it.

the solution is to unlink the item. This can be done manually, but when you copy using coed, you can directly unlink the item like this:

SPListItem.Copy(SPContext.Current.Web.Url + "/" + _doc.Url, _publicLibUrl + _doc.Name);
SPListItem fileToUnlink = site.AllWebs[_publicSiteName].GetListItem(_publicLibUrl + _doc.Name);
if (fileToUnlink != null)
{
fileToUnlink.UnlinkFromCopySource();
fileToUnlink.Update();}

The first try I forgot to add the .Update(). It is required to to this, if not, your change is not updated and the item is not unlinked. The unlinking cannot be undone.