473,698 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2807
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.Writ e,
FileShare.None) ;

--
Regards

John Timney
Microsoft MVP

"Guy_B" <Gu***@discussi ons.microsoft.c om> wrote in message
news:79******** *************** ***********@mic rosoft.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
7323
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
14544
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 not be accessed because its locked by another process or something (I cant get it to do it now - because I want it to crash...) Is there a way to check whether a file is locked by another process befre
2
1896
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 three buttons on a windows form that provide three options for the user the process goes like this user clicks button one and a web service is called that dwnloads a list
4
8708
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
19933
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 it, it throws an exception. How to solave this problem? So second process can wait until first process completes its processing on the file. Thanks in advance
13
11141
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 writes a specific string to the log file. My original program (MKS Toolkit shell program) which keeps running "grep" checking the "exit string" on the "log files". There are no file sharing problem.
6
6023
by: elake | last post by:
I found this thread about a pst file in Windows being locked and I am having the same issue. http://groups.google.com/group/comp.lang.python/browse_thread/thread/d3dee5550b6d3652/ed00977acf62484f?lnk=gst&q=%27copying+locked+files%27&rnum=1 The problem is that I have a script that can find the pst files on every machine in my network and back them up to a server for safe keeping. The problem is that when Outlook is running it locks the...
8
8857
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. After I bounced IIS, then it worked fine. log4net.dll is in the Bin directory. What is going on here - this makes no sense to me.
7
1811
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 Windows VISTA environment but I do not get this error when testing in a Windows XP environment on another computer. I close the file and even use the Dispose command to make sure all resources are released. Is this a problem with VISTA or my computer...
5
3050
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 temporary conversion folder. Then it converts it to the desired file format and copies the file to the output folder specified. Then it deletes the converted file from the temporary conversion folder. Then it attempts to delete the copied input file...
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.