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 通过文件扩展名剥离附件的主要内容,如果未能解决你的问题,请参考以下文章