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.

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

1 Answer 1

1

Try this inside the catch block:

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

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.