Frage

I have set up a local development environment on sharepoint for the sake of testing event recievers.

I can build and deploy the following code.

However when I deploy the following code it does not change the document's title property when a file is uploaded.

 using System;
 using System.Security.Permissions;
 using Microsoft.SharePoint;
 using Microsoft.SharePoint.Utilities;
 using Microsoft.SharePoint.Workflow;

 namespace chrisclementen.chrisclementen
 {
/// <summary>
/// List Item Events
/// </summary>
public class chrisclementen : SPItemEventReceiver
{
    /// <summary>
    /// An item was added.
    /// </summary>
    public override void ItemAdded(SPItemEventProperties properties)
    {
        base.ItemAdded(properties);
        properties.ListItem["Title"] = "test synchro";
        properties.ListItem.Update();
    }

    /// <summary>
    /// An item was updated.
    /// </summary>
    public override void ItemUpdated(SPItemEventProperties properties)
    {
        base.ItemUpdated(properties);
        properties.ListItem["Title"] = "test synchro";
        properties.ListItem.Update();
    }


}
 }
War es hilfreich?

Lösung

1- Check the Element.xml of the Event Receiver and add the listUrl Attribute :

<Receivers ListUrl="Lists/YourListUrl"> // For simple Lists

or

<Receivers ListUrl="Documents"> //For Document Libraries

Edit :

You Element.xml should look like this. Please dont copy it from here just replace the List url in your Element.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListUrl="Lists/YourListUrl">
    <Receiver>
      <Name>chrisclementenItemAdded</Name>
      <Type>ItemAdded</Type>
      <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
      <Class>chrisclementen.....</Class>
      <SequenceNumber>10000</SequenceNumber>
      <Synchronization>Synchronous</Synchronization>
    </Receiver>
    <Receiver>
      <Name>chrisclementen ItemUpdated</Name>
      <Type>ItemUpdated</Type>
      <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
      <Class>chrisclementen.chrisclementen.Ichrisclementen </Class>
      <SequenceNumber>10000</SequenceNumber>
      <Synchronization>Synchronous</Synchronization>
    </Receiver>
  </Receivers>
</Elements>

if it still not working : Add this line like in the exemple.

<Synchronization>Synchronous</Synchronization>

Let me know if this was helpfull for you.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top