Last active
August 29, 2015 14:19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// An item is being updated. | |
/// </summary> | |
public override void ItemUpdated(SPItemEventProperties properties) | |
{ | |
base.ItemUpdated(properties); | |
// Get Current ListItem | |
SPListItem item = properties.ListItem; | |
// Check if Title is Null Or Empty. | |
// Title will be empty in case user is uploading the new document without any property. Same time Title field should be mandatory field. | |
if (string.IsNullOrEmpty(item.Title)) | |
{ | |
// Get Before Properties | |
var beforeProperties = properties.BeforeProperties; | |
// Loop and update all the properties | |
foreach (System.Collections.DictionaryEntry prop in beforeProperties) | |
{ | |
try | |
{ | |
if (prop.Key.ToString().Equals("vti_title")) | |
{ | |
item["Title"] = beforeProperties[prop.Key.ToString()]; | |
} | |
if (item.Fields.ContainsField(prop.Key.ToString())) | |
{ | |
var field = item.Fields.GetField(prop.Key.ToString()); | |
// Check if it is valid property | |
if (item.Fields.ContainsField(prop.Key.ToString()) && !field.ReadOnlyField && !field.Sealed) | |
{ | |
item[prop.Key.ToString()] = beforeProperties[prop.Key.ToString()]; | |
} | |
} | |
} | |
catch | |
{ } | |
} | |
// Update the ListItem | |
EventFiringEnabled = false; | |
item.SystemUpdate(); | |
EventFiringEnabled = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment