Search code examples
sql-server-2008ssissql-server-2012ssis-2012ssis-2008

How to find the Flat file which is currently updating record into it


In SSIS In a folder there are many flat files and by using for each loop container we are processing it one by one. If any new file is placed in the folder and it is still in copying mode. Then, We should not take it for continue process. We should process Only fully copied file alone to our next process.

How can we achieve this? Please give your suggestions.


Solution

  • Best way I have done this in the past is to use a C# Script Task and try to open the file - If the file is still being copied you will get an error (which you Catch). Then you can set a boolean variable to conditionally process the file if the Open worked.

    EG: Boolean b = true;

            FileStream f;
    
            try
            {
                f = new FileStream("C:\\Test\\Test.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.None);
            }
            catch (IOException e)
            {
                if (e.Message == "hello")
                {
                    b = false;
                }
            }