1

I have developed an SSIS package to create ZIP file in the particular location.I'm able to send email attachment of the ZIP file.Now, I wanted to do following:

If my file size is less then 1MB then send email with attachment; Else, send only email notification(no attachment).I wanted to make this configurable also.

So, I wanted to know, is there any way in SSIS, to check for the file size and do the necessary action??

bapi
  • 1,903
  • 10
  • 34
  • 59

1 Answers1

5

You need an SSIS Variable to help in this endeavor. At a minimum, you would want a Boolean, call it IncludeAttachment.

After your Execute Process Task, or however you are creating the zip, you will need to run a Script Task that will take the path to that newly created zip and optionally, another variable which contains your threshold (today it's 1MB but tomorrow it's 5).

Inside your script task, you're going to use the Length property of FileInfo

FileInfo f = new FileInfo(pathToZip);
if (f.Length > thresholdValue)
{
    Variables["IncludeAttachment"].Value = false;
}
else
{
    Variables["IncludeAttachment"].Value = true;
}
billinkc
  • 59,250
  • 9
  • 102
  • 159
  • When i'm taking a variable of type byte and setting its value as 1MB(1048576 byte), its showing me error: "1048576" is not a valid value for byte, the value either too large or too small for a unsigned byte.Then I changed the type to "sbyte", still its giving same error: "the value either too large or too small for a signed byte" How can I resolve this issue? What type i should take? – bapi Nov 13 '13 at 06:24
  • In addition to this: Its seems that "f.Length" will not give size of file on disk. Here: http://stackoverflow.com/questions/1380839/how-do-you-get-the-file-size-in-c – bapi Nov 13 '13 at 10:39
  • I think it will be like this: double ifileLength = (finfo.Length / 1048576); //return file size in MB ....I'm still doing some testing for this, to get a confirmation. – bapi Nov 13 '13 at 13:36