Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 ...

share|improve this question
    
Is the document that the code is trying to change locked or checked out? –  Ryan Erickson Mar 14 '13 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 '13 at 23:43
add comment

2 Answers

u can use item.SystemUpdate()

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

share|improve this answer
    
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 '13 at 13:58
add comment

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

share|improve this answer
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 '13 at 12:43
    
Happy to hear that you have resolved the issue, btw how did you find that the threshold is causing the error.? –  Karthik Jaganathan Dec 11 '13 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 '13 at 13:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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