2

I am developing a SharePoint job. In the public override void Execute(Guid targetInstanceId) method, my code goes:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
  int count = this.WebApplication.Sites.Count;
  for (int i = 0; i < count; i++)
  {
    using (SPSite site = new SPSite(this.WebApplication.Sites[i].ID))
    {
      using (SPWeb web = site.OpenWeb())
      {
         web.AllowUnsafeUpdates = true;
         documentLibraries = web.GetListsOfType(SPBaseType.DocumentLibrary);
         foreach (SPDocumentLibrary documentLibrary in documentLibraries)
         {
           foreach (SPListItem document in documentLibrary.Items)
           {
             document[periodicReviewStatusField] = "Review is needed";
             document.UpdateOverwriteVersion();
           }
         }
         web.AllowUnsafeUpdates = false;
      }
    }
  }
});

My code fails on the first document update in the line document.UpdateOverwriteVersion(); with the error message:

Additions to this Web site have been blocked. Please contact the administrator to resolve this problem.

I know for a fact that the site collection is not locked (which was the only answer I found online) and that there are no locks on any of the documents. Can you help me resolve this? It's killing me for a couple of days now ...

2
  • Is the document that the code is trying to change locked or checked out? Mar 14, 2013 at 23:41
  • No the document is neither locked nor checked out. Actually, the code even goes and unlocks the document prior to updating, just in case.
    – Boris
    Mar 15, 2013 at 23:43

2 Answers 2

1

Have you gone through all solutions provided here ?

or

check the document library settings and find out that document library was set NOT to require check out although versioning was enabled. Just try to set to require check out.

Note:

RunWithElevatedPrivileges only works if the current thread is using impersonation, i.e. IIS. Used in other code (timer jobs, console applications, workflow, etc.) it will have no effect. By default the timer service runs as the farm service account specified in the Configuration Wizard. You can verify this in Windows Services.

Source

3
  • 1
    Actually, the problem was that there are a few lookup properties in that library. It wouldn't update because it exceeded the allowed threshold. So what I did was I went to Central Administration and increased the threshold. All the confusion started because of that wrong SharePoint error message. SP Dev team must be ill-fated or something :)
    – Boris
    Dec 11, 2013 at 12:43
  • Happy to hear that you have resolved the issue, btw how did you find that the threshold is causing the error.? Dec 11, 2013 at 12:54
  • I moved on to the next issue as soon as I resolved it (the problem happened in March 2013), and now I don't even remember what led me to the resolution.
    – Boris
    Dec 13, 2013 at 13:08
0

u can use item.SystemUpdate()

UpdateOverwriteVersion() gives the error you mentioned if the item's version is published

1
  • Ok, so how do I tell if it is published or not? Is it just by checking it's major/minor version? And the second question would be is there a way to bypass the Published situation and still use UpdateOverwriteVersion()?
    – Boris
    Mar 22, 2013 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.