Multiple Attachments


Badge +5

Hi, How do I manage to attach multiple files to an Mail Server Event?  Could I do it with just one DataField?  If yes, how do I pass the value to the DataField, lets say, for 15 attachments?  Do I loop each filename and add it to the DataField?  Can I use comma "," or semi-colon ";" as the delimeter?  Can I use a delimeter?


FilePath.Text = FileName1 & ", " & FileName2 & "," & ..... FileName15


 HELP


2 replies

Badge +5

Hi


Would these attachments all be located on the k2 server?


If this is the case you could :


Create a Mail Server event and select an attachment by browsing to a file so that you have a template.Switch to code view and remove the code where it sets the attachment string and create a string type array by splitting your datafield value using the delimiter you prefer.


char dlChar = ';';
string[] attachments = K2.ProcessInstance.DataFields["MyAttachments"].Value.Split(dlChar); 


And then iterate through the attachments and add them to the mail object.


 foreach(string attachment in attachments)
  {
   try
   {
    if(attachment.Trim() !="")
    {    
    objAttachment = new System.Web.Mail.MailAttachment(attachment);
    objMsg.Attachments.Add(objAttachment);
    }
   }
   catch (System.Exception ex)
   {
    throw new System.Exception(ex.Message);
   }
  }



Hope this helps


Gert 


 

Badge +5
Wow!!! Thank you so much for the help. I will definitely try this.

Reply