I'm developing an solution where people will upload Excel documents .CSV to a document library.

I will handler the SPItemEventReceiver / ItemAdded to handler when someone upload a new Excel to the document library because I need to treat data inside that document.

So, I'm trying to figure out how can I Open/treat that document just before it will be uploaded to get data inside that document.

Please, can someone give me a light?

Thank You,

Juliano —

1 Answer 1


You can use itemAdded or ItemCheckedIn and get the file from SPItemEventProperties as below:

SPListItem item = properties.ListItem;
SPFile document = item.File;
byte[] byteArray = document.OpenBinary();

//work with the file here


Depending on your security settings and permission levels for users who upload the documents you may need to run the code with elevated privileges.

Note: ItemAdded is 'after event' (asynchronous by default), so it fires after the file is uploaded. Unfortunately you can't get the file in ItemAdding but you can make ItemAdded synchronous (only SharePoint 2010 and up) if needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.