3

I want the following code to prevent adding any file to a library and silently continue with no error. However when an item is adding and I cancel the result with the CancelNoError flag SharePoint still displays error message File Not Found. Can the ItemAdding Event display nothing and just silently continue? What am I missing here?

Thanks!

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

            using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (clientContext != null)
                {
                    clientContext.Load(clientContext.Web);
                    clientContext.ExecuteQuery();

                    result.Status = SPRemoteEventServiceStatus.CancelNoError;
                }
            }

            return result;
        }
1

I faced the same problem and solved it with just one move action :). What is happening during an "Adding" event is that the item is added just before the client context is closed. In this case it is before the close brace of the using statement. So you must return the event result (with error status in it) within the using context - and not outside of it.

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

        using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
        {
            if (clientContext != null)
            {
                clientContext.Load(clientContext.Web);
                clientContext.ExecuteQuery();

                result.Status = SPRemoteEventServiceStatus.CancelNoError;
            }

            return result;
        }
    }
1
  • Sounds plausible. Can you please highlight the difference between your code and mine? So far I see no difference. – ChiliYago Sep 17 '14 at 0:01

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.