0

Using VS2012, I'd like to create an event handler for a document library. When a document is added to a library, an entry is created in a list. That list entry contains all the metadata from the library as well as a hyperlink to the document in the library. It also synchronizes changes to the list metadata when the item is changed in the library and removes the list entry if the document is deleted out of the library.

1
  • I'd question this requirement, duplication of data is never a good thing. All the document metadata is going to be there in the document library. Aug 22, 2013 at 14:59

1 Answer 1

0

I agree with PirateEric regarding the duplication of data. But if you really need to do this, here is your answer:

Please note that this will not occur in a single event receiver, you will need to do this in:

  • Item Added
  • Item Updated
  • Item Deleting

    //This is for item Added, you can do the rest yourself, as it works on nearly the same logic private void CopyItem(SPListItem sourceItem, string destinationListName) { //Copy sourceItem to destinationList SPList destinationList = sourceItem.Web.Lists[destinationListName]; SPListItem targetItem = destinationList.Items.Add(); foreach (SPField f in sourceItem.Fields) { //Copy all except attachments. if (!f.ReadOnlyField && f.InternalName != "Attachments" && null != sourceItem[f.InternalName]) { targetItem[f.InternalName] = sourceItem[f.InternalName]; } } targetItem["LinkToOrignalFile"] = sourceItem.File.Url; targetItem.Update(); }

Kind regards, JP

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.