Programmatically creating files for use by separate application

Dear forum,
How do I create a file in .Net, and then 'release' it so that another application can use it

I am creating an application that involves programmatically creating a directory structure containing a number of text files.
Once the files are created, I programmatically use the DTS (Data Transformation Services) object model to fireup DTS packages which insert data into the files.
But the DTS packages are getting an error - the file is in use by another application...which is presumably the .Net application that is creating the files.

I am really stuck on this one, a bit of a novice with System.IO. Any help will be much appreciated.




Answer this question

Programmatically creating files for use by separate application

  • Shimon273

    Hi -
    I have found that it works to enclose the statements in code blocks and then explicitly call the garbage collector.

    Eg>
    {
       FileInfo f = new FileInfo(path);
       f.Create();
    }
    GC.Collect;

    But is there a better way to achieve this

  • TPM01

    Hi,

    The Create method returns a FileStream object which you need to close.


    FileInfo f = new FileInfo(path);
    FileStream objFileStream = f.Create();
    objFileStream.Close();


     



    Regards,
    Vikram



  • Raymond Tong

    Hey - many thanks that really helped me learn
  • Programmatically creating files for use by separate application