Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Sharepoint 2013 - Object reference not set to an instance of an object

$
0
0

Hi

I hope someone can help me ...

I need to create an event receiver on a task list in sharepoint 2013.

With visual studio I am connected to the site, I created a new empty project sharepoint 2013 and I added an event receiver. My purpose is to verify a field before saving.

The code I wrote is as follows:

public override void ItemAdding(SPItemEventProperties properties)
        {
            if (properties.List.Title != "Richieste Implementazione")
            {
                base.ItemAdding(properties);
                return;
            }

            string StatoRichiesta = Convert.ToString(properties.ListItem["Stato Richiesta"].ToString()) ;
            if (VerificaStato(StatoRichiesta) == false)
            {
                properties.ErrorMessage = "In fase di creazione lo stato non piò essere diverso da 'Da Prendere in carico'";
                properties.Status = SPEventReceiverStatus.CancelWithError;
                properties.Cancel = true;
            }
            base.ItemAdding(properties);
        }

        public bool VerificaStato(string StatoRic)
        {
            if (StatoRic != "Da prendere in carico")
            {
                return false;
            }
            return true;
        }

The error I get :

string StatoRichiesta = Convert.ToString(properties.ListItem["Stato Richiesta"].ToString()) ;

NullReferenceException was unhandled by user code

Object reference not set to an instance of an object.

I hope I was clear and sorry for my english.

Thanks to all!!


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>