I dunno if this was supported in WSS2 or not, but in WSS3, when a file is copied to a new destination, a link is stored which indicates where the new document is copied from.
In the database, you can see this by running the query:
SELECT tp_dirname, tp_leafname, tp_copysource, tp_hascopydestinations, tp_guid, * FROM ALLUSERDATA
The tp_CopySource column holds the URL of the source document from which the given file is copied from. If you simply change the URL here, you can point it to any file you want. If the file is a copy, then the following information bar will be displayed on top of the file properties in the properties page:
However, it's not so obvious how to do this programmtically. First, I tried using the CopyTo() method of SPFile. Aside from not having the desired effect, this method does not seem to allow copying files across site boundaries (for example, from a root site to a document workspace -- for that, you have to use the Add() method on the Files property of the target SPWeb).
On my second attempt, I tried to set the "Copy Source" property of the file.
foreach (object key in file.Properties.Keys) { Console.Out.WriteLine("{0} : {1}", key, file.Properties[key]); }
Iterating through the properties of an SPFile instance, I found that one of the properties, was "Copy Source" (internal name of "_CopySource") and in fact, held the URL of the source document. I tried to set this value and update the file, but this was unsuccessful yet again.
On my third attempt, I came across the CopyTo() method on the SPListItem class and this did it for me Conveniently, it also allows you to copy an item across site boundaries.
I felt so stupid afterwards because it should have been obvious that I had to use the CopyTo() method on the SPItem because the SPItem is also where the UnlinkFromCopySource() method is located.
Remember Me
newtelligence dasBlog 1.8.5223.0
This site is a combo blog/portfolio for me, Charles Chen.
Sign In