question

shubhammathur-3260 avatar image
0 Votes"
shubhammathur-3260 asked shubhammathur-3260 edited

Custom Error Message is not displaying - Remote Event Receiver on Item Adding event

I have create Remote Event Receiver on Item Adding, I want to restrict to create Folder in Document Library. It is working fine but my error message is not displaying.

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

         using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
         {
             if (clientContext != null)
             {
                 if (properties.EventType == SPRemoteEventType.ItemAdding)
                 {                        
                     try
                     {                          
                       //  string strQuery = curHttpContext.Request.QueryString["empid"];
                       //  WriteToLog("QueryString", strQuery, clientContext);
                       if (!properties.ItemEventProperties.AfterProperties.ContainsKey("vti_filesize"))
                         {
                             clientContext.Load(clientContext.Web);
                             clientContext.ExecuteQuery();
                             string errMsg = "Folder is not supported";
                             result.Status = SPRemoteEventServiceStatus.CancelWithError;
                             result.ErrorMessage = errMsg;
                         }
                            
                     }
                     catch(Exception ex)
                     {                           
                             WriteToLog("Exception",ex.Message,clientContext);                            
                     }
                 }
             }
             return result;
         }

     }


Can anyone give me snippet for access the query string parameter in Remote Event Receiver for Item Adding Event ?

office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered shubhammathur-3260 edited

Hi @shubhammathur-3260,

SPRemoteEventServiceStatus.CancelWithError will only trigger when there is exception thrown, if there is no exception when running the code, then it won't display the error message and cancel the event receiver.



If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks @MichaelHan-MSFT for your reply.

From the above code I am not able to create folder as well as able to cancel the triggered event but not able to show error message. It is showing me the SharePoint by default message.
97728-image.png


0 Votes 0 ·
image.png (23.6 KiB)

Can you(@MichaelHan-MSFT ) update me on accessing Query string parameters in Remote Event Receiver in Item Adding event. Is it possible?

0 Votes 0 ·