Solved

extracting a text fle from network folder C# IO how do I check if file is ready

Posted on 2010-11-18
3
409 Views
Last Modified: 2012-05-10
Visual studio 2008 - C# - on windows.
H I ned to watch a network folder (Source Folder) for a text file to land there. Once I see the file I need to move that file to somewhere else (Destination).
However the 3Rd party system that writes the file to Source may still be sriting contents or may not even be finished copying the file to Source when I attempt to move it to destination.
I want to wait till the 3RdPart app is finished with the file , then move it.
What is the coding I should use ? and what classes and methods can I use please?
Please paste some simple code lines rather than directing me to links if possible.
Thanks.
0
Comment
Question by:indikad
3 Comments
 
LVL 3

Accepted Solution

by:
saifikram_md earned 400 total points
ID: 34169363
FileSystemWatcher is the best way to use. follow the link below

FileWatcher
0
 
LVL 17

Assisted Solution

by:Zhaolai
Zhaolai earned 100 total points
ID: 34170250
Try this:
If Len(strFileName) > 0 AndAlso System.IO.File.Exists(strFileName) Then
            'need to make sure that the file is ready to be copied.
            Do While True
                'try to open the file for read. If failed, try again, until it's ready
                Dim tmp As System.IO.StreamReader = System.IO.File.OpenText(strFileName)

                If tmp IsNot Nothing Then
                    tmp.Close()
                    tmp.Dispose()
                    System.Threading.Thread.Sleep(10)
                    Exit Do
                End If
                System.Threading.Thread.Sleep(10)
            Loop
        End If

Open in new window

0
 

Author Closing Comment

by:indikad
ID: 34185696
Thanks very much
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question