SSIS文件验证

时间:2015-03-05 15:50:07

标签: ssis

我是SSIS的新手。我在源位置有多个文件(平面文件)。 在浏览每个文件时,SSIS包需要确定文件是.txt还是.csv格式。如果任何文件不是.txt或.csv格式,则应将文件移动到Error目录并发送电子邮件,提示每个无效文件的文件格式无效。电子邮件消息应包含文件名。< / p>

你能帮我找一个解决方案吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

你可以这样做。

      //set string builder to create html for email. This will be 
      //set to a string variable in your ssis package
        System.Text.StringBuilder objMsg = new System.Text.StringBuilder();

        objMsg.Append("<html><head><style type='text/css'>table td {border: solid 1px black; padding-left: 10px; padding-right: 10px;}</style></head><body><div style='font-family: tahoma, geneva, verdana; font-size: 10pt;'>");
        objMsg.Append("<p>The following table contains files that do not match the required format.</p>");
        objMsg.Append("</div></body>");

      string[] files = Directory.GetFiles("directory");

        foreach (string file in files)
        {
            // if extension is invalid then append table for html email payload
            if (Path.GetExtension(file).ToLower() == ".txt" || Path.GetExtension(file).ToLower() == ".csv") 
            {
                objMsg.Append("<p style='margin-left: 30px;'>Details:</p><table style='margin-left: 30px; font-family: monospace; font-size: 9pt; text-align: right; width: 5in;'><tr style='background-color: silver; color: white; font-weight: bold;'><td style='width: 100%'>File Name</td></tr>");

                    objMsg.Append("<tr>");
                    objMsg.Append("<td>" + Path.GetFileName(file) + "</td>");
                    objMsg.Append("</tr>");
             File.Move(file, "errordirectory" + Path.GetFileName(file));
            }
        }
Dts.Variables["your user variable here"].value = objMsg.ToString();

我为粗略的格式道歉,我正努力在工作中快速完成这项工作。

这将通过源目录中的文件循环,并向字符串构建器对象添加一个条目,该对象将最终在html中构建一个表,其中包含一条前导消息,其中显示“下表包含与之不匹配的文件”要求的格式。“

在If语句中,它还会将标识的文件移动到新目录中。

运行此步骤后,您可以将添加了html的字符串变量指定为电子邮件步骤的正文。

相关问题