csharp 通过文件扩展名剥离附件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 通过文件扩展名剥离附件相关的知识,希望对你有一定的参考价值。

//GAC:System.Data.dll
using System;
using System.Collections.Generic;
using System.IO;
using Kofax.KCS.ImportConnector.Messages;
using Kofax.KCS.ImportConnector.Scripting;
using System.Data.OleDb;


namespace Kofax.KCS.ImportConnector.ScriptingSample
{
    public class SampleDocumentScript : IDocumentScript2
    {
        #region IDocumentScript2 Members


        /// <summary>
        /// Called before the import content and import order is determined
        /// Body and attachment content and import order can be maniuplated in this function 
        /// </summary>
        /// <param name="messageBody">A readonly instance of the message being imported</param>
        /// <param name="messageBody">The list of received message bodies</param>
        /// <param name="attachments">The list of received message attachments</param>
        /// <param name="extension">Reserved for future use</param>
        public void ManageMessageFiles(ReadonlyMessage message,
                               List<Attachment> messageBody,
                               List<Attachment> attachments,
                               object extension)
        {
            List<string> skipExts = new List<string> { "png", "htm", "txt" };

            // Exclude specified body.
            foreach (Attachment msgBody in messageBody)
            {
                string origExt = (Path.GetExtension(msgBody.OriginalFileName) ?? "").Replace(".", "");

                if (skipExts.Contains(origExt.ToLowerInvariant()))
                {
                    msgBody.DoImport = false;
                }
            }

            // Exclude specified attachments.
            foreach (Attachment attachment in attachments)
            {
                string origExt = (Path.GetExtension(attachment.OriginalFileName) ?? "").Replace(".", "");

                if (skipExts.Contains(origExt.ToLowerInvariant()))
                {
                    attachment.DoImport = false;
                }
            }

        }

        /// <summary>
        ///  Called before a message import into KC is started
        /// </summary>
        /// <param name="indexFields">The list of index fields defined in the configured document class. If document class not defined this will be empty.</param>
        /// <param name="folderFields">The list of folder fields defined in the configured folder class. If folder class not defined this will be empty.</param>
        /// <param name="batchFields">The list of batch fields defined in the configured batch class.</param>
        /// <param name="messageBody">The list of received message bodies</param>
        /// <param name="attachments">The list of received message attachments</param>
        /// <param name="extension">Reserved for future use.</param>
        public void BeforeMessageImport(IDictionary<string, string> indexFields,
                                IDictionary<string, string> folderFields,
                                IDictionary<string, string> batchFields,
                                List<Attachment> messageBody,
                                List<Attachment> attachments,
                                object extension)
        {

        }

        /// <summary>
        /// Called before a KC document is created in KC
        /// </summary>
        /// <param name="indexFields">The list of index fields defined in the configured document class. If document class not defined this will be empty.</param>
        /// <param name="folderFields">The list of folder fields defined in the configured folder class. If folder class not defined this will be empty.</param>
        /// <param name="batchFields">The list of batch fields defined in the configured batch class.</param>
        /// <param name="messageBody">The list of received message bodies</param>
        /// <param name="attachments">The list of received message attachments</param>
        /// <param name="extension">Reserved for future use.</param>
        public void BeforeDocumentImport(IDictionary<string, string> indexFields,
                                  IDictionary<string, string> folderFields,
                                  IDictionary<string, string> batchFields,
                                  List<Attachment> messageBody,
                                  List<Attachment> attachments,
                                  object extension)
        {


        }

        #endregion
    }
}

以上是关于csharp 通过文件扩展名剥离附件的主要内容,如果未能解决你的问题,请参考以下文章

如何通过亚马逊发送带有自定义文件扩展名附件的电子邮件?

csharp 上传文件并将其作为附件发送到电子邮件#email #attachment

无法打开流式文件附件

包含扩展字符的 MIME 附件名称失败

附件名称和文件扩展名在电子邮件 *.eml 中不起作用

csharp 返回附件web api c#