Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 28th, 2004, 10:02 AM
Registered User
 
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using the FileSystemWatcher to copy Created file

HI, I use the FileSystemWatcher in c# to copy a file created by Biztalk to another directory, but it copies a zerop length file to the new dir. If I copy a file into the watched dir, it works ok, but not from biz...

I assume biztalk creates the file, fills it with data, then saves it. How would I be able to wait till it is ok to read the file?

Here is the code:

Code:
        private void Form1_Load(object sender, System.EventArgs e)
        {

            fsWatcher.Path = @"C:\EDI\Orders\2_EDI_Output_3_IServer_Input";

            fsWatcher.Created += new System.IO.FileSystemEventHandler(this.FileCreated);

            // Begin watching.
            fsWatcher.EnableRaisingEvents = true;

        }

        private void FileCreated(object sender, System.IO.FileSystemEventArgs e)
        {
            try
            {
                string myPath = e.FullPath;
                string myFile = e.Name;

                System.IO.FileInfo myFileInfo = new System.IO.FileInfo(myFile) ;

                string myAttibs = myFileInfo.Attributes.ToString();
                while (myFileInfo.Attributes.ToString()  != "18446744073709551615")
                {
                    string x = "waiting";
                }

                System.IO.File.Copy(myPath,@"C:\EDI\Aperaks\3_XML_Input\" + myFile,true);
            }
            catch (System.IO.IOException ex)
            {
            System.IO.IOException myex = ex;
            }
            catch (System.Exception ex)
            {
                System.Exception myex = ex;
            }
        }
Thanks
Enrico
iProc

 
Old October 28th, 2004, 11:39 PM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use NotifyFilter option of the FileSystem watcher to wait till it is ok to read file.

i.e. add the code

fsWatcher.NotifyFilter = NotifyFilters.LastAccess;

This will raise the event only after the write is complete.



It is not how much we do,
but how much love we put in the doing.

-Mother Theresa





Similar Threads
Thread Thread Starter Forum Replies Last Post
Why Created 2 Excel file? cyclone9 SQL Server 2000 0 September 8th, 2008 04:20 AM
Display file Access and Created date scoobie Java Basics 1 March 16th, 2007 06:53 AM
Viewing asp created file chayz Classic ASP Basics 1 January 14th, 2005 08:47 AM
Macro to copy data from one file to a 2nd file chadpodsednik Excel VBA 1 October 29th, 2004 10:40 AM
Can't get image file created on localhost Bob Bedell Dreamweaver (all versions) 8 October 6th, 2003 09:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.