2

I had this piece of code to capture every form submission and send the form input as an email. However, we found that the code behave differently between CM and CD environment.

   public class FeedbackSendEmailAction : WffmSaveAction
   {
       public virtual void Submit(ID formid, AdaptedResultList fields)
       {
           try
           {
               string attachPath = string.Empty;
               foreach (AdaptedControlResult formField in fields)
               {
                   if (formField.FieldName.Equals("Attachment"))
                   {
                       attachPath = formField.Value;
                   }

               }
               ...
               //send email etc
           }
           catch (Exception ex)
           {
             //do some logging
           }
       }
   }

On CM environment, the formField.Value returns path where the item is stored (e.g. ). While on CD environment it will returns Sitecore.WFFM.Abstractions.Actions.PostedFile as if it was a string and we can't cast it. Decompiling the assembly gave us the following:

//Sitecore.WFFM.Abstractions.Actions
[Serializable]
public class AdaptedControlResult : ControlResult
{
    public new string Value
    {
        get;
        private set;
    }
}

//Sitecore.WFFM.Abstractions.Actions
[KnownType(typeof(PostedFile))]
[Serializable]
[SoapInclude(typeof(PostedFile))]
[XmlInclude(typeof(PostedFile))]
public class ControlResult
{
    public object Value
    {
        get;
        set;
    }
}

I am aware that the AdaptedControlResult extends ControlResult that exposes Value as object and we might be able to fetch the PostedFile in ControlResult's Value field with ease if we cast the AdaptedControlResult into ControlResult.Unfortunately, it did not work as expected and returns null..

My question are:

  • Why does it behave differently?
  • How to fetch the attached file byte[] or Stream in CD environment if its possible?
  • Do you have “Client Action” checked for this save action? If checked, the code executes on the CD server. If not checked, then the form save action gets processed via the event queue. Client Action is a very common box to check whenever dealing with custom save actions. My hunch is that by not checking it, the serialization process of storing the form submission improperly casts the value as that unexpected type name. – jrap Feb 13 '18 at 3:29
  • its checked. anything else i should check? – Bagus Tesa Feb 13 '18 at 3:49
  • Bagus have a look at my answer here, it might help you: sitecore.stackexchange.com/questions/5482/… – Adam Seabridge Feb 19 '18 at 19:20
0

See my comment above about a similar issue I was having. Changing the setting below should mean your posted file is available on CD Servers too and will have a value:

<?xml version="1.0" encoding="utf-8"?>

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <settings>
            <setting name="WFM.IsRemoteActions" value="false" />
        </settings>
    </sitecore>
</configuration>
  • hmm, its not exactly empty though AdaptedControlResult.Value returns Sitecore.WFFM.Abstractions.Actions.PostedFile. and i am sure that we have the WFM.IsRemoteActions not set on CD. I will let you know once i've checked on this. thank you for the answer. – Bagus Tesa Feb 20 '18 at 1:20
  • No problem. Take a look at some of the code Jonathan has in his post to read the file value and see how you get on: jonathanrobbins.co.uk/2015/02/18/… – Adam Seabridge Feb 20 '18 at 1:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.