Genpact Cora Knowledge Center

Support

Write a Custom Attachment Provider for a Message Wizard

Use the API to write a custom attachment provider to use in a message wizard.

using PNMsoft.Sequence.Messaging;
using PNMsoft.Sequence.Net;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
 
namespace SequenceCustomAttachmentsArray
{
 public class CustomAttachments
 {
 public MyAttachmentInfo GetAttachment(string path)
 {
 return new MyAttachmentInfo(path);
 }
 
 public MyAttachmentInfo[] GetAttachments(string pathDir)
 {
 List<MyAttachmentInfo> attachments = new List<MyAttachmentInfo>();
 
 string [] fileList = Directory.GetFiles(pathDir);
 
 foreach (var filePath in fileList)
 {
 attachments.Add(new MyAttachmentInfo(filePath));
 }
 
 return attachments.ToArray();
 }
 }
 
 public class MyAttachmentInfo : IMessageAttachmentInfo
 {
 internal MyAttachmentInfo(string physicalPath)
 {
 if (File.Exists(physicalPath))
 { //read the file from the provided path and fill set the attachment properties.
 Content = File.ReadAllBytes(physicalPath);
 FileInfo info = new FileInfo(physicalPath);
 ContentLength = (int)info.Length; ContentType =MimeTypes.GetContentType(info.Name);
 FileName = info.Name;
 }
 }
 
 
 public byte[] Content { get; set; }
 public int ContentLength { get; set; }
 public string ContentType { get; set; }
 public string FileName { get; set; }
 }
 
 
}