1

I have a document library on my SharePoint online site, when a user uploads a file in the library a c# itemAdded event is triggered to read the file and store the information in a separate list. This all works perfect. My problem comes in where i need to write any exception errors to a field in the document library. I have a multiline text field in the library already and there are several methods in my code, each method needs to be able to write to the field. How can i do this from the catch method. Any Help would be greatly appreciated.

  • In case of exceptions is the document get uploaded properly? – Amal Hashim Dec 8 '14 at 14:46
  • Yes the document is uploading properly, but if an exception is hit, the error is not being stored. – Egor Dec 8 '14 at 15:03
1

Try this inside the catch block:

catch(Exception ex)
{
    SPListItem item = properties.Listitem;
    item["MultiTextFieldName"] = ex.Message;
    item.Update();
}
  • I will obviously have to pass the properties to all the methods to use this code? – Egor Dec 8 '14 at 15:21
  • You need to pass the ListItem. This is the best way to get hold of that object. – Amal Hashim Dec 8 '14 at 15:24
  • @Amsal Thank you very much for the help, got it working. – Egor Dec 8 '14 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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