Quantcast
Channel: Developing Apps for SharePoint 2013 forum
Viewing all articles
Browse latest Browse all 8089

App web document library, renaming a file in RER itemadded event results in error

$
0
0

On Prem environment, Vis Studio 2013 App for SharePoint project.  I create an  OOTB instance of a document library with no versioning and no check in/out and a OOTB remote event receiver for the ItemAdded event.  In the RER elements.xml I set the ListUrl to the library and set Synchronization to Synchronous. In the svc.cs I change the title and filename as follows

public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();
            Uri appWebUrl = new Uri(properties.ItemEventProperties.WebUrl);
            using (ClientContext clientContext = new ClientContext(appWebUrl))
            {
                if (clientContext != null && properties.EventType == SPRemoteEventType.ItemAdded) //ItemAdded event = synchronous in element.xml
                {
                    List list = clientContext.Web.Lists.GetById(properties.ItemEventProperties.ListId);
                    ListItem item = list.GetItemById(properties.ItemEventProperties.ListItemId);
                    item["Title"] = "New Title";
                    item["FileLeafRef"] = "newName.docx";
                    item.Update();
                    clientContext.ExecuteQuery();
                }
            }
            return result;
        }

When I debug run I get a SharePoint File Not Found error message. 

When I close the error dialog I go to the list page.  I do not get an edit form.  If I refresh,  I see the new title and filename in the list view.

I have also tried file.moveto instead of renaming the FileLeafRef, but with no success.

If I comment out the FileLeafRef update, everything works.

How do I set the filename? 

Thanks




Viewing all articles
Browse latest Browse all 8089

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>