using openxml in SharePoint 2013 remote event receiver

Hello Experts,

Please has anybody used openxml with a SharePoint 2013 or remote event receiver.  I am trying to retrieve the the document history version(not just the version number) when a document is updated in a document library.

Kindly assist with any guidance.

R,

Shola

May 19th, 2015 1:48am

Hello shola,

Yes you can use open xml in RER.

Please refer this blog to attached an RER is Hostweb>>http://blogs.msdn.com/b/kaevans/archive/2014/02/26/attaching-remote-event-receivers-to-lists-in-the-host-web.aspx

public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            switch (properties.EventType)
            {
                case SPRemoteEventType.AppInstalled:
                    HandleAppInstalled(properties);
                    break;
                case SPRemoteEventType.AppUninstalling:
                    HandleAppUninstalling(properties);
                    break;
                case SPRemoteEventType.ItemAdded:
                    HandleItemAdded(properties);
                    break;
                case SPRemoteEventType.ItemUpdating:
                    HandleItemUpdating(properties);
                    break;
            }
         } 



private void HandleItemUpdating(SPRemoteEventProperties properties)
        {
            using (ClientContext clientContext =
                TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (clientContext != null)
                {
                    try
                    {
                        List photos = clientContext.Web.Lists.GetById(
                            properties.ItemEventProperties.ListId);
                        ListItem item = photos.GetItemById(
                            properties.ItemEventProperties.ListItemId);
                        clientContext.Load(item);
                        clientContext.ExecuteQuery();
                        item["Title"] += "\n added by RER " + System.DateTime.Now.ToLongTimeString();
                        item.Update();
                        clientContext.ExecuteQuery();


                        Microsoft.SharePoint.Client.File file = item.File;
                        ClientResult<Stream> data = file.OpenBinaryStream();
                        // Load the Stream data for the file
                        clientContext.Load(file, f => f.ListItemAllFields, f => f.Name);
                        clientContext.ExecuteQuery();

From File you can take the file versions collection. Or you can refer Open XML and do a particular task.

If you want to perform it after item added event, you can go ahead with Process One way event.

Free Windows Admin Tool Kit Click here and download it now
May 20th, 2015 12:21am

Hi,

According to you description, my understanding is that you want to retrieve document version history when updating a document in document library.

If you want to retrieve the document version history in a remote event receiver, I suggest you can use Client Object Model to achieve it. Open XML SDK is used to read the document content not version history.

Here are some code demos for your reference:

Retrieve Document Library Version History using Client Side Object Model

Programmatically get document Version History using client object model

Thanks

Best Regards

May 20th, 2015 1:32am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics