2
votes

SharePoint 2010 in document library using event receivers when uploading a file using itemadded event. In the event get the properties of the file it will changed because the file contains same properties in the custom tab of properties of the file. so the SPListItem properties will not come, so how to clear the file custom properties when uploading a file in sharepoint please help me.

I am set to ItemAddedCol is default value is set to false, but i will shown in true. Problem is I am uploading a file that extension is .ppt. The file properties and go to custom tab set add some fileds like ItemAddedCol, File Size. So these values are taking how to clear these custom fields in item added event.

string size = Convert.ToInt32(listitem["File Size"]);
statusupdate = Convert.ToString(listitem["ItemAddedCol"]);
1

1 Answers

1
votes

I'm not sure if this is what you want, but when you upload file into document library, setting custom properties invokes item updating events. You should be able to write your event receiver for ItemUpdated (or ItemUpdating) event and clear properties you want here.

So the code can look something like this:

public virtual void ItemUpdated(SPItemEventProperties properties, bool isCheckIn)
{
    try
    {
        this.EventFiringEnabled = false;

        SPListItem listItem = properties.ListItem;

        //clear value in your custom column
        listItem["myCustomColumnName"] = null;

        listItem.Update(); //or listItem.SystemUpdate()
    }
    finally
    {
        this,EventFiringEnabled = true;
    }
}

I haven't tested this code, so let me know if you have any issues when running it.