SharePoint runs a method when an item is added to the library

I have a library and I want to run some code when an element is added to populate some additional columns. Is there a way that I can run this code automatically. Where would I add it? It would also be possible to have a screen to be able to edit code parameters. Just a few, pointing to the correct dodging, would be great.

Will this be a case of creating a workflow?

0
source share
4 answers

Workflows are not a way to solve them. You must create an event listener for the item. The reason I say this is because it seems that you need some kind of code to run only after the element is added. Since you do not need to maintain state, then workflows are not an appropriate solution to this problem. Here's what you do: create a new class in Visual Studio and inherit it from SPItemEventReceiver. Override the method ItemAdded()and put your logic there. Example:

public class MyItemEventReceiver : SPItemEventReceiver
{
    public override void ItemAdded(SPItemEventProperties properties)
    {
        base.ItemAdded(properties);
        // do your stuff
    }
}

This code will be called after the item is added. If you need the code to execute before adding an element, you will override the method ItemAdding(). The way my company deploys event receivers is a bit different, but it's a book-to-method using Elements.xml:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="101">
    <Receiver>
      <Name>My Event Receiver</Name>
      <Type>ItemAdding</Type>
      <SequenceNumber>1000</SequenceNumber>
      <Assembly>AssemblyName, Version=1.0.0.0, culture=neutral, PublicKeyToken=[token]</Assembly>
      <Class>Namespace.Class</Class>
      <Data></Data>
      <Filter></Filter>
    </Receiver>
  </Receivers>
</Elements>

. , , . , , , <Data> . properties.ReceiverData . , <Filter> - WSS 3. , .

+3

, . .

EventHandler, . , ( Async), . - , EventHandlers.

0

, Workflow EventReceivers ( ) . , , .

, , . SharePoint. , , . , .

, EventReceivers - , , , , . EventReceiver, . EventReceiver , .

0
source

The good things about workflows are that the user can see a trace of what is happening in the workflow history.

I wrote about Event Receivers from start to finish: http://koenvosters.wordpress.com/2009/07/31/howto-create-an-event-handler-for-sharepointmoss-2007/

0
source

Source: https://habr.com/ru/post/1727211/


All Articles