Question

Is it possible to configure

  • where a file is uploaded to (it's currently being upload direct to the media library)
  • how a file is displayed in the Form Report (currently a long link string that can't be easily read nor clicked on)
  • which file types are allowed (e.g. images only)
  • how the file will be forwarded by email

We have a multi-site solution, so ideally we'd like to be able to set these on a form by form basis, but be able to configure defaults as Solution Default > Site default > Form specific.

I've already seen that there are code examples for limiting file size, which is something else we'd like to do.

So are any of these directly configurable, or will we need to code them?

Edit: Web Forms For Marketers 2.3.0 rev.131126 Running on Sitecore 7.0 rev. 140120 (7.0 Update-4).

Was it helpful?

Solution

Yes you can define path where file will upload in case of file field. Please see attached screenshot.

enter image description here

OTHER TIPS

All file upload settings are located under: /sitecore/System/Modules/Web Forms for Marketers/Settings/Field Types/Simple Types/File Upload

The pipeline ran when a file is uploaded is "formUploadFile"; so you could reflector existing one and amend to add required changes.

To upload allowed file types use below link.

http://sitecorejunkie.com/2014/06/16/restrict-certain-files-from-being-uploaded-through-web-forms-for-marketers-forms-in-sitecore-an-alternative-approach/

here you can get idea that how you can restrict mime types in WFFM.

To send attachment in email you can create custom send email action in Sitecore and use below code

// send email with attachments

public static bool SendEmailWithAttachments(string To, string From, string Subject, string Message, string atchmnt1, string atchmnt2, string atchmnt3) {
    bool result = true;
    try {
        MailMessage mailMsg = new MailMessage();
        // mailaddress of sender
        MailAddress mailFrom = new MailAddress(From);
        mailMsg.From = mailFrom;
        // mail addresses for recipients
        string[] mailAddressList = To.Split(',');
        foreach (string str in mailAddressList) {
            try {
                MailAddress mailTo = new MailAddress(str.Trim());
                mailMsg.To.Add(mailTo);
            }
            catch { }
        }
        mailMsg.Subject = Subject;
        mailMsg.Body = Message;
        mailMsg.IsBodyHtml = true;
        if (!string.IsNullOrEmpty(atchmnt1)) {
            mailMsg.Attachments.Add(ReadAttachment(atchmnt1));
        }
        if (!string.IsNullOrEmpty(atchmnt2)) {
            mailMsg.Attachments.Add(ReadAttachment(atchmnt2));
        }
        if (!string.IsNullOrEmpty(atchmnt3)) {
            mailMsg.Attachments.Add(ReadAttachment(atchmnt3));
        }
        var smtp = new SmtpClient(Sitecore.Configuration.Settings.MailServer, Sitecore.Configuration.Settings.MailServerPort);
        smtp.Send(mailMsg);
    }
    catch {
        result = false;
    }
    return result;
}
// get attachement by media item id
public static Attachment ReadAttachment(string value) {
    MediaItem mediaItem = null;
    ItemUri itemUri = ItemUri.Parse(value);
    if (itemUri != null) {
        Item item = Database.GetItem(itemUri);
        if (item != null) {
            mediaItem = new MediaItem(item);
        }
    }
    // create attachment using media item properties
    Attachment attachment = new Attachment(mediaItem.GetMediaStream(), string.Join(".", new string[] { mediaItem.Name, mediaItem.Extension}), mediaItem.MimeType);
    return attachment;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top