2013-08-02 76 views
1

修改在SharePoint項目中,我有事件接收器非常重要,直到現在爲項目部署了7個版本的客戶端。這些版本之一是如此不穩定和緩慢。我的意思是有時更新一個項目它sticks.and這隨機發生。處理錯誤的最佳方法:文件'FileName'已被SHAREPOINT system

注意:他們的網絡速度是好的,問題是在項目中。

我檢查了代碼,並發現有錯誤文件「文件名」特惠服務SHAREPOINT \系統進行了改造導致一個循環的方式,sometimes.this是ItemUpdatedItemAdded事件接收器來更新代碼SPListItem

base.EventFiringEnabled = false; 
bool tryAgain = false; //used to handle "The file has been modified by SHAREPOINT\system" 
do 
{ 
    tryAgain = false; 
    try 
    { 
     try 
     { 
      if (_item.File.CheckOutType == SPFile.SPCheckOutType.Online || _item.File.CheckOutType == SPFile.SPCheckOutType.Offline) 
       { 
        try 
        { 
          _item.File.CheckIn("prevent checkout/locked error"); 
        } 
        catch (Exception ex) { } 
       } 
      _item.SystemUpdate(true); 
     } 
     catch (Exception ex) 
     { 
      throw ex; //-- used to handle "The file has been modified by SHAREPOINT\system" 
     } 
    } 
    catch (Exception ex) //-- used to handle "The file has been modified by SHAREPOINT\system" 
    { 
     if (ex.Message.ToLower().Contains("has been modified by")) 
     { 
      System.Threading.Thread.Sleep(1000 * 2); 
      tryAgain = true; 
     } 
     else 
     { 
      this.HandleException(ex, ""); 
     } 
    } 
} while (tryAgain == true); 

這個while循環有以下狀態:

1項被更新的第一次,而且也沒有例外

2更新原因提到的異常,它會在迭代幾次後更新

3更新原因提到的異常,並且它在一個循環中停留,即使在200次迭代後也不會更新。

這個問題的情況下,項目是不穩定的,有時工作如此緩慢。什麼是處理這種情況的最佳方式?

回答

2

快速搜索吐出來了,所提到改變了elements.xml中的事件接收器定義執行的同步,而不是異步(這是默認)幾篇文章:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> 
    <Receivers ListTemplateId="850"> 
     <Receiver>  
     <Synchronization>Synchronous</Synchronization> 
     </Receiver>  
    </Receivers> 
</Elements> 

文章我把這個來自: http://onlinecoder.blogspot.co.uk/2013/07/splistitemupdate-file-has-been-modified.html

+0

謝謝,但同步使它慢!我的問題是速度! –

0

可能已經太晚了..我在2017年面臨同樣的問題..解決方案沒有爲我工作..我做的是在ItemAdded事件接收器我正在閱讀文件,並在閱讀後我創建了一個新的線程來根據文件中的值更新列。它的工作..

+0

你可以發佈完整的代碼嗎? –

相關問題