views:

206

answers:

3

Hi, Is there a programmatic way to differentiate between an addition of a New document and the Upload of a document in a Document Library? (Moss 2007)

I want to make a document upload raise an ItemAdded event only after some required fields have been filled, by default it is raised as soon as the upload itself is done by browsing to the file and clicking OK...

Thanks

+1  A: 

You may be able to check the before and after properties of the ItemAdded event, but I doubt there will be a reliable difference.

Nat
A: 

I am afraid this is very hard to do programmatically because

  • When a document is uploaded using New, there is only a create event
  • When a document is uploaded using Upload, there is a create event when the file is uploaded and an update when (and if) the properties are updated. But the properties are updated with a system update so the update event does not fire.

After the document is added I agree with Nat that there will be no reliable difference.

But Jon Powell wrote an article how to separate between New and Upload with help from a workflow in the following article. You could do the same by adding your required logic in that workflow.

Hope this helps,

Henrico

Henrico Dolfing
I tried checking is this is the first Version of the Document being checked in. If I can make sure that it is the first version, I can use the ItemCheckedIn event. But, I get the following values everytime.properties.ListItem.Versions.Count (always 1)properties.ListItem.Versions.VersionID (always 512)properties.ListItem.Versions.Count.VersionLabel (always "1.0")///If I check for fileSPFile sf = curweb.GetFile(properties.ListItem.File.ToString());SPFileVersionCollection vercol = sf.Versions;here, vercol is empty every time. Not sure how to get version information for that document.
A: 

Assuming that Major Versioning is enabled for the Document Library,

Doc Lib Settings > Versioning Settings > Major Versioning

The follwing values can be used to find out if it is the first version in the ItemCheckedIn event,

properties.ListItem.Versions[0].VersionID (512 is the value for the first Version ) properties.ListItem.Versions[0].VersionLabel ("1.0" is the value for the first Version)

Note-Verions[0] stands for the current version.

This way one may do the ItemAdded functionality in ItemCheckedIn event receiver.