473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Is a file locked by another process ? How can I check ?

Hi I am using the filesystem watcher to pick up files as they are dropped
into a folder - the files are output file from another system and I have no
control over that.

When 'watcher raises the event that a new file has appeared then sometimes I
can read the file even tho it is still being written but it is incomplete.
Other time a file access error occurs.

I need to write a test that will see if any other process is still using
the file or if it is complete. Im using a vb.net 2005 and Net v2 A windows
service hosts the filesystem watcher which intances a class to process the
files that appear.
Mar 13 '06 #1
2 2776
Hello Guy_B,

U need to iterate through the processes to find the file handler that belongs
to one of the processes (u need pinvoke calls)
Googling in dotnet groups to find sample.

G> Hi I am using the filesystem watcher to pick up files as they are
G> dropped into a folder - the files are output file from another system
G> and I have no control over that.
G>
G> When 'watcher raises the event that a new file has appeared then
G> sometimes I can read the file even tho it is still being written but
G> it is incomplete. Other time a file access error occurs.
G>
G> I need to write a test that will see if any other process is still
G> using the file or if it is complete. Im using a vb.net 2005 and Net
G> v2 A windows service hosts the filesystem watcher which intances a
G> class to process the files that appear.
G>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Mar 13 '06 #2
An easy way would probably be to try to open it exclusively, if its being
written to you'll get an exception you can trap and re-check.

I think the syntax is:
FileStream myFile = new FileStream(name, FileMode.Open, FileAccess.Write,
FileShare.None);

--
Regards

John Timney
Microsoft MVP

"Guy_B" <Gu***@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
Hi I am using the filesystem watcher to pick up files as they are dropped
into a folder - the files are output file from another system and I have
no
control over that.

When 'watcher raises the event that a new file has appeared then sometimes
I
can read the file even tho it is still being written but it is incomplete.
Other time a file access error occurs.

I need to write a test that will see if any other process is still using
the file or if it is complete. Im using a vb.net 2005 and Net v2 A windows
service hosts the filesystem watcher which intances a class to process the
files that appear.

Mar 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Pekka Niiranen | last post by:
Hi, I have used the following example from win32 extensions: -----SCRIPT STARTS---- import win32file import win32con import win32security import pywintypes
10
by: Grant | last post by:
Occasionally when I try and save a document: ----------------------- xmlDoc.Save(Application.StartupPath + @"\Config.xml"); ----------------------- I get this error saying that the file could...
2
by: Bruce Wiebe | last post by:
hi all im having a problem accessing a text file on my hard disk after ive created it and added some text to it it would appear that the file is still locked. What happens is this i have...
4
by: Xero | last post by:
hello. how do you check if a file (say, a txt one) is being used by another process? thanks. -- Xero http://www.chezjeff.net My personal web portal
1
by: ABCL | last post by:
Hi All, I am working on the situation where 2 different Process/Application(.net) tries to open file at the same time....Or one process is updating the file and another process tries to access...
13
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it...
6
by: elake | last post by:
I found this thread about a pst file in Windows being locked and I am having the same issue. ...
8
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; I copied a new set of files over to my ASP.NET dir (and subdirs) on our test server. This replaced every file for the app. When I first then tried to bring it up, I got the below error. ...
7
by: =?Utf-8?B?UGFycm90?= | last post by:
I am receiving a "file is being used by another process" error message whenever I try to access a text file that I had previously created and then closed. This only happens when I test in a...
5
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a .Net web service that converts the MODCA files to tif or png file format. This web service runs on a 2003 server. This web service first copies the MODCA file to be converted to a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.