Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    Sep 06, 2013 @ 07:35
    Nathan Woulfe
    0

    Working with 'save as file' workflow

    Within the workflow of a form I need to save the submitted data to a file and then attach that file to an email which is then sent to a specified address.

    How do I get the file details (ie name and path).

    It's a bit of an odd request given that the form data could easily be included in the email body, but I'm just doing what I'm asked (or trying to at least).

    Any guidance would be awesome.

  • Jesper Hauge 298 posts 487 karma points c-trib
    Sep 09, 2013 @ 18:30
    Jesper Hauge
    1

    Hi Nathan,

    If you've got some coding skills, this could probably best be achieved through a custom workflow.

    You can see documentation on how to create workflows here

    In the workflow code you could new up a mail message, and then create a memoru stream to handle the attachment of a file. Something like:

    private void SendMyMail() {
        using (var msg = new MailMessage()) 
        {
            msg.To.Add(new MailAddress("[email protected]"));
            msg.From = new MailAddress("[email protected]");
            msg.Subject = "Yoursubject";
            msg.BodyEncoding = Encoding.UTF8;
            msg.IsBodyHtml = true;
            msg.Body = "<p>Here's your mail message content";
    
            using (var stream = new MemoryStream())
            {
                // create attachement content
                var fileText = "The text to be attached, probably assembled using a StringBuilder";
                var fileBytes = Encoding.UTF8.GetBytes(fileText);
                stream.Write(fileBytes, 0, fileBytes.length);
                stream.Seek(0, SeekOrigin.Begin);
    
                var contentType = new ContentType 
                    {
                        MediaType = MediaTypeNames.Application.Octet,
                        Name = newOnePager.Title + ".txt"
                    };
                var attachment = new Attachment(stream, contentType);
                msg.Attachments.Add(attachment);
            }
    
            using (var client = new SmtpClient())
            {
                client.Send(msg);
            }
        }
    }
    

    Regards
    Jesper Hauge

Please Sign in or register to post replies

Write your reply to:

Draft