Event Receiver Infopath

 HI,

Can someone direct me how to submit InfoPath item with an event receiver with elevated privileges:

Scenario:

1. User has only read access to the form library

2. User submits the InfoPath form; "item Adding" event receiver intercepts/overrrides the submit button in Infoapth and executes the submission with elevated privileges.

Can this be done?

Please include the code snippet if you can

Thanks

May 15th, 2015 1:16pm

You can call the 'Submit' data connection in your InfoPath code-behind to submit your form to library (alternative way if you do not want to submit via InfoPath Rules).

Under SPSecurity.RunWithElevatedPrivileges you will call instantiate DataConnection class and call Execute() method to submit the form via code.

No need to write an event receiver code to submit the form that would probably won't work in case of InfoPath Form. Simply put this logic into your InfoPath code-behind (Code Editor)

In the below code "Submit" is my Submit data connection name. You should write your Submit data connection name. If you have similarly named it as "Submit" then no need to change it.

Ensure in InfoPath Designer under Submit Options you have configured the data like this:



The code-behind logic to submit form under SPSecurity.RunWithElevatedPrivileges

public void FormEvents_Submit(object sender, SubmitEventArgs e)
  {
    try
    {
      SPSecurity.RunWithElevatedPrivileges(delegate()
      {
        // your business logic.
        // any code
    
        DataConnection spConn = DataConnections["Submit"];
        spConn.Execute();
        e.CancelableArgs.Cancel = false;
      });
    }
    catch (Exception ex)
    {
      e.CancelableArgs.Message = "The form cannot be saved" + ex.Message;
      e.CancelableArgs.Cancel = true;
    }
  }

Free Windows Admin Tool Kit Click here and download it now
May 17th, 2015 8:57am

Thanks this makes sense.

Just confirm the below for me please.

Also, what does this stand for e.CancelableArgs.Cancel = false;

In other words, I DO NOT reference the data connection in the InfoPath button rules, instead I place this code on the "code-behind" section of the button?

N

May 17th, 2015 10:39pm

Yes. Calling Submit from code-behind is enough.
Free Windows Admin Tool Kit Click here and download it now
May 18th, 2015 2:42am

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

Other recent topics Other recent topics