?
Solved

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

Posted on 2010-11-18
3
Medium Priority
?
414 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
saifikram_md earned 1600 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 400 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

762 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