Windows Develop Bookmark and Share   
 index > Windows Forms General > Programmatically creating files for use by separate application
 

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.


Al Hibbs  Thursday, July 14, 2005 4:24 PM

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

Vikram  Thursday, July 14, 2005 6:26 PM
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?
Al Hibbs  Thursday, July 14, 2005 5:33 PM

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

Vikram  Thursday, July 14, 2005 6:26 PM
Hey - many thanks that really helped me learn
Al Hibbs  Thursday, July 14, 2005 9:26 PM

You can use google to search for other answers

Custom Search

More Threads

• How to get treeView newName after LabelEdit ?
• Creating Custom Explorer Bars, Tool Bands, and Desk Bands (The .NET Way)
• Drawing with GDI+ and DC
• child form shows menustrip unnecessarily when automatically merging with MDI parent form
• Retaining image
• Popup Menu - How to position and show?
• removing ApplicationExit event handlers
• How to modify Windows Form Designer Generated code In InitializeComponent() method programmitically?
• Selected Checkboxes(using CheckedListBox) not retrieving filtered Data
• Chart control and its deployement