views:

171

answers:

3

Hi!

I have a site in SharePoint and I want to custom delete from a list. So, I'm creating the

 public class ListItemEventReceiver : SPItemEventReceiver
 {
 public override void ItemDeleting(SPItemEventProperties properties)
        {
            if (properties.ListTitle.Equals("Projects List"))
            {
               Projects pr = new Projects();
               string projectName = properties.ListItem["Project Name"].ToString();
               pr.DeleteProject(projectName);
            }
         }
}

Where 'Projects' class has 'DeleteProject' method who deletes the item. But it's doing nothing :( I mention that everything it's ok in Feature.xml

Where am I wrong?

+1  A: 

A couple of things to check:

  • Is your list item reciever connected to the list, so that it fires?
  • Does the user that causes the trigger to fire have the the right to delete items?
  • Is there any programming error in DeleteProject?

Try putting in some logging to see how far it is running.

Edit

Could the problem be here:

           string projectName = properties.ListItem["Project Name"].ToString(); 

Is the list item called "Project Name" with a space in the name?

Edit 2

From your comments, the combination of authentication and connection string means that it is the security context of the logged on user that is being used against the database. Check the rights of your user.

Shiraz Bhaiji
1. Yes, I'ved tried this: " properties.ErrorMessage = "projectName :" + projectName; properties.Cancel = true; " in if clause and the event it's fireing and displayes the project name corectly.2. I'm the farm administrator, and site administrator with full controll over this site.3. DeleteProject method it's right, because I'ved tryed it in some other aplication (c#) and it's works fine.I really have no clue....
Clodin
Yes, the item it's with a space in the name.... but it works fine... it just don't execute pr.DeleteProject(projectName); . I think the only problem it's with user permision, but add/update works fine on user (administrator) I can't see why delete isn't working
Clodin
Delete is a specific SQL permission, it could be that you are running in the security context of Network Service, and therefore reduced rights
Shiraz Bhaiji
I must say that for the first time I was using Windows Authentication for my SharePoint site and everything worked ok with my event receiver feature for add/update/delete. But now I am on form-based authentication and just add and update works fine... no delete :(
Clodin
Are you using impersonate = true in your web.config?
Shiraz Bhaiji
<connectionStrings> <add name="Entities" connectionString="metadata=res://*/Entities.csdl|res://*/Entities.ssdl|res://*/Entities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=Server;Initial Catalog=Database;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /> <add name="AuthConnectionString" connectionString="SERVER=Server;DATABASE=Database; TRUSTED_CONNECTION=true;" /> </connectionStrings>These are my connection strings.... first it's for the feature,the second one for form-based authentication
Clodin
<authentication mode="Forms"> <forms loginUrl="/_layouts/login.aspx" /> </authentication> <identity impersonate="true" />And yes... impersonate attribute it's set to 'true'... from here it's the problem?
Clodin
A: 
  1. Yes, I've tried this:

    properties.ErrorMessage = "projectName :" + projectName;
    properties.Cancel = true; 
    

    in if clause and the event it's firing and displays the project name corectly.

  2. I'm the farm administrator, and site administrator with full control over this site.

  3. DeleteProject method it's right, because I've tried it in some other application (c#) and it's works fine.

I really have no clue...

Clodin
A: 

Hi Clodin,

If event is firing and the only method pr.DeleteProject(projectName); is not working properly then it is difficult to guess what is wrong. If it is not confidential, please post your code and then I shall be in better position to identify what is wrong.

By the way, are you calling .Update() Method on list?

Please check out this link http://msdn.microsoft.com/en-us/library/ms431920.aspx

One more thing to care about is Item*ed and Item*ing events. It is better to use Before or After properties as appropriate in case of Item*ing events.

Regards,

Azher Iqbal

Azher Iqbal