Itemupdating which wasn t
After hours of debugging and testing, I discovered that it was only clearing my column when Item Updating was triggered and the value of my column had already been set properly and hadn’t changed. I stepped through the code with the VS debugger and found that the properties.So I made the obvious change and removed the piece of my code that skips explicitly setting the column value if it has already been set. After Properties[COLUMN_NAME] had the correct value for the entire method, but some time after the Item Updating method finished the value was cleared, unless I had explicitly set the value during that pass.For more information, see the other posts in this series: I was recently tasked to automatically set a document ID value in a Share Point 2007 document library.(In Share Point 2010, an excellent document ID feature is included out of the box) I figured it would be easy since Share Point supports calculated columns.Hopefully the material here will save you from some of the suffering I went through.There are several Event Receiver classes that you can extend from that each get called at different times: You can also directly add an event handler through the SPEvent Receiver Definition class, but this is usually not necessary for most common tasks.One of the big selling points for Share Point 2007 is the ability to have MS Word automatically detect the fields that are set up in Sharepoint and make those values available within the document.
I was surprised by how much work was involved in getting it to behave consistently.Just spin up a thread that waits for Share Point to be finished modifying the file and list item, then sets the auto field value.When this tactic is used, the auto value gets set in Share Point and in the document for all reasonable test cases. when you copy using Word Save As to add a new document, when you use the Windows Explorer View, or when you use the standard Share Point Web UI to Add or Edit the document.) One thing to keep in mind is that you can’t determine how many times the code will be run.The reverse, when Share Point pushes the values defined in the list into the word document, is called property demotion.This works quite well, until you have an event handler that automatically sets the value of a field in Share Point. //Global variables to store values for the worker thread private Guid List ID; private Guid Item ID; private Guid Site ID; private String Field Value; public override void Item Updated(SPItem Event Properties properties) public override void Item Added(SPItem Event Properties properties) private void Set Custom Value() The logic is fairly simple.