I want to change the Document ID through code, the why is out scope for this question. I do have a reason, and I can explain this if you want, but please accept the fact that I have the need to change this using C#.
The following code works fine in a console application:
SPFile oFile = oWebToChangeDocID.GetFile(sDestination + sFileName);
//Change the document ID
oFile.Item["_dlc_DocId"] = "TESTID";
oFile.Item["_dlc_DocIdUrl"] = "http://rms2010:1001/sites/site/_layouts/DocIdRedir.aspx?ID=TESTID, TESTID";
oFile.Item.SystemUpdate();
But I need to execute this code in a custom WorkFlow activity (which I have written). When this code is executed from within this activity, however, it does not always work...
I've tried using different threads (including thread.sleep, to wait). I've also changed the code to use an asmx webservice (in this webservice I also tried threads, etc) without success.
As mentioned, this does work on some documents, but if I execute the same code (using my console application) on a document which failed using the workflow activity, it does work!
I do not understand what I am missing, any input is welcome!
Note: I use elevated permissions in both the workflow activity and the WebService.