Domanda

Ho un ricevitore dell'articolo che implementa ItemUpdated() per elaborare un articolo dopo che è stato caricato su una libreria di documenti. Tutto funziona bene Se aggiungo documenti alla libreria "Documenti condivisi" predefiniti, quando viene aggiunto un nuovo documento, ItemUpdated() viene attivato normalmente. Tuttavia, se creo una nuova libreria di documenti nella stessa raccolta del sito, ItemUpdated() non viene attivato quando caricando un nuovo documento su di esso. Ma quando carichi un'altra versione o rinomina il documento ecc., ItemUpdated() viene attivato normalmente - non è semplicemente attivato sul caricamento dell'oggetto. Esempio tipico:

    .
  • I carica 'DOC1' per documentare la libreria - ItemUpdated() no Esegui (ma esegue se la libreria dei documenti è "documenti condivisi");
  • Carica un'altra versione di 'Doc1' - ItemUpdated() Esegue come previsto;
  • Io rinominato 'DOC1' - ItemUpdated() ESEGUTI Come previsto.

    Mi è stato portato a credere che l'ordine degli eventi quando si aggiunge un documento è normalmente:

    .

    Aggiunta - Aggiunto - Aggiornamento - Aggiornato

    Allora, perché il mio ItemUpdated() non viene attivato per le biblioteche diverse da "documenti condivisi"? C'è qualche impostazione che potrebbe causare questo?

    Si noti che per vari motivi, non posso eseguire l'elaborazione all'interno di ItemAdded().

    elements.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Receivers ListTemplateId="101">
        <Receiver>
          <Name>MyEventReceiverItemUpdated</Name>
          <Type>ItemUpdated</Type>
          <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
          <Class>MyProject.MyEventReceiver.MyEventReceiver</Class>
          <SequenceNumber>1000</SequenceNumber>
        </Receiver>
      </Receivers>
    </Elements>
    
    .

    Codice:

    public class MyEventReceiver : SPItemEventReceiver
    {
        // On document upload, this method is only entered if I upload to "Shared Documents"
        public override void ItemUpdated(SPItemEventProperties properties)
        {               
            base.ItemUpdated(properties); // doesn't get called either
            MyMethod(properties);
        }
    }
    
    .

È stato utile?

Soluzione 2

It seems I have found a solution. I implemented ItemAdded() besides the original ItemUpdated() in the event receiver. Inside, I force a subsequent call to ItemUpdated() like this:

public override void ItemAdded(SPItemEventProperties properties)
{            
    base.ItemAdded(properties);
    properties.ListItem.UpdateOverwriteVersion();            
}

Note that UpdateOverwriteVersion "updates the item without creating another version of the item" (MSDN). This results in a call to ItemUpdated() when a new item is added; in addition, it doesn't create a new version of the item (i.e. you don't end up with 2 versions when you first add a new item). So far, this works as expected for all document libraries, with and without versioning.

Altri suggerimenti

Do you have additional columns in one library or another? It seems that makes a difference in terms of whether ItemUpdating() fires on upload. Have a look at this post. The key sentence there is,

"the events that are triggered during when a document is Added to a Document Library MAY include ItemUpdating and ItemUpdated. But only if there are additional fields included in the process."

So you might want to play around with different library configurations in your environment so you can better understand how this "feature" of SharePoint impacts your system.

Also, I can appreciate that there may be reasons to avoid ItemAdded. If ItemUpdated continues to be an issue for you, and you'd be willing to share some detail about why ItemAdded is undesirable in your environment, consider asking a separate question here about how to make ItemAdded work in your system.

Good luck!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top