I am trying to add few details for a item that is added to a list to SQL database table using a stored procedure, it works perfectly but when I upload multiple files it adds all of the items into the database, whereas My requirement is to just add 1 any of them Item details in the database, not sure if I can do it or not, here is the code.
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
// System.Diagnostics.Debug.Assert(false);
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SqlConnection sqlConnection = new SqlConnection(ConnectionString());
SqlCommand command = new SqlCommand("InsertItemDetails", sqlConnection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@SiteURL", SqlDbType.VarChar).Value = properties.WebUrl;
command.Parameters.Add("@ItemName", SqlDbType.VarChar).Value = properties.ListItem.Title;
command.Parameters.Add("@TimeItemAdded", SqlDbType.DateTime).Value = DateTime.Now;
sqlConnection.Open();
command.ExecuteNonQuery();
sqlConnection.Close();
});
}
I think I can add a filter for URL as if it already exists in database then delete that row and add a new Item, but not sure if it will be effective solution.
