473,903 Members | 5,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find out if other process is accessing a file?

Hi

Is it possible to find out if another process is using a paticular file
(xml)? There does not seem to be anything useful in the File och Filestream
class for this purpose.

regards

Carl
Apr 2 '07 #1
9 5414
If you attempt to open the file and get an exception, another process is
using it. Use a try/catch block.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Carl" <ca***@communit y.nospamwrote in message
news:OW******** ******@TK2MSFTN GP03.phx.gbl...
Hi

Is it possible to find out if another process is using a paticular file
(xml)? There does not seem to be anything useful in the File och
Filestream class for this purpose.

regards

Carl

Apr 2 '07 #2
Hi Carl,

Only kernel mode code can enumerate which files are opened by other
processes, for example, the Handle utility
(http://www.microsoft.com/technet/sys...eads/Handle.ms
px) is using a driver to list all open handles by all processes.

Therefore your objective to do it in .NET might not be possible.

However, if a file is exclusively opened by other processes, an exception
will be thrown when you try to open it again in .NET.

Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 3 '07 #3
Ok, Thanks for your replies.

Too bad there is no easy way. I'm waiting for a lenghy file operation to
complete, therefore it would be nice to check to see when there are no
handles (at least from the app I'm waiting for). Unfortunately the file does
not seem to be locked, by the other process (I'm only reading it), but what
saves me is that it is in XML format, so it will not be well formed if I
grab it to early.

Regards

Carl

"Walter Wang [MSFT]" <wa****@online. microsoft.comwr ote in message
news:oY******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Carl,

Only kernel mode code can enumerate which files are opened by other
processes, for example, the Handle utility
(http://www.microsoft.com/technet/sys...eads/Handle.ms
px) is using a driver to list all open handles by all processes.

Therefore your objective to do it in .NET might not be possible.

However, if a file is exclusively opened by other processes, an exception
will be thrown when you try to open it again in .NET.

Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Apr 3 '07 #4
On Apr 3, 6:08 am, "Carl" <c...@community .nospamwrote:
Ok, Thanks for your replies.

Too bad there is no easy way. I'm waiting for a lenghy file operation to
complete, therefore it would be nice to check to see when there are no
handles (at least from the app I'm waiting for). Unfortunately the file does
not seem to be locked, by the other process (I'm only reading it), but what
saves me is that it is in XML format, so it will not be well formed if I
grab it to early.

Regards

Carl

"Walter Wang [MSFT]" <waw...@online. microsoft.comwr ote in messagenews:oY* *************@T K2MSFTNGHUB02.p hx.gbl...
Hi Carl,
Only kernel mode code can enumerate which files are opened by other
processes, for example, the Handle utility
(http://www.microsoft.com/technet/sys...AndThreads/Han...
px) is using a driver to list all open handles by all processes.
Therefore your objective to do it in .NET might not be possible.
However, if a file is exclusively opened by other processes, an exception
will be thrown when you try to open it again in .NET.
Sincerely,
Walter Wang (waw...@online. microsoft.com, remove 'online.')
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ps/default.asp...
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.
If you try to open the file exclusively, you will get an exception if
it is still in use regardless of how other programs have opened it.

Chris

Apr 3 '07 #5
I think we need to first know how the other process is writing to the xml
file: sometimes a process will append some content to a file then close it
and repeat this until all content are written to the file. If the process
is keeping the file open for writing, normally you will have to specify
FileShare.ReadW rite or FileShare.Write to open it before the other process
closes it. Since you mentioned that you're able to read the file, if you're
not specifying this FileShare flag, I suspect the other process is not
keeping the file open. You can determine this by using FileMon
(http://www.microsoft.com/technet/sys...k/Filemon.mspx) to
monitor the other process's file activity.

If the other process it not keeping the file open for writing, then you
really don't know whether or not it finished writing to the file.
About the FileShare stuff, you can find a related thread here:

http://groups.google.com/group/micro...es.csharp/brow
se_thread/thread/9adcc0203e0806e 5/68232ed6863c63a 3?lnk=st&q=file &rnum=5#6823
2ed6863c63a3

(Just scroll down and see the last few messages)

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 4 '07 #6
Thanks alot for your recommendations and tips. I will investigate how the
other process is using the file and take actions from that!

regards

Carl
Apr 4 '07 #7
Hi Carl,

Have you got a chance to find out how the other process is using the file?
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 9 '07 #8
Unfortunately not at the moment, but perhapse in a few days.

regards

Carl
Apr 10 '07 #9
Hi Carl,

Thanks for the update.

Please feel free to reply here whenever you've got updated information on
the issue.
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 11 '07 #10

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

Similar topics

1
7600
by: Dan Jones | last post by:
I'm writing a script to process a directory tree of images.  In each directory, I need to process each image and generate an HTML file listing all of the images and links to the subdirectories. Just about every source I can find on the 'net for processing subdirectories points you at Find::Find.  However, I'm trying to do something like this: enter directory open INDEX, ".\index.html" print INDEX HTMLheader
2
1605
by: Joerg Battermann | last post by:
Hello there, I was wondering how I can check whether I am allowed to read a certain file or not? Some of e.g. XP's files are not readable, not even by the Administrator, and when trying to open a file for reading, it throws an exception (e.g.: {"The process cannot access the file \"C:\\Documents and Settings\\Joerg\\Local Settings\\Application Data\\Lookout Software\\Lookout\\Data.Outlook\\Log Files\\log.txt\" because it is being used by...
1
2993
by: vaughn | last post by:
I'm trying to access a text file that was created by another process but I keep getting the contents of the file before the external process modified it. I believe the previous process left it open and doesn't let me access it. Is it possible for me to close the file before using in order to make sure that I have complete access? Even if it's not open, I'd like to make sure. Thanks.
10
14431
by: Sorin Dolha [MCSD .NET] | last post by:
I would like to start a process from C# code as another user. The C# code is executed as the ASPNET user because it relies in a Web Page class, and I would like that the process will run as another user to gain the required rights for execution (the external process needs to create a mailbox in Exchange, so it needs to be run as an Exchange Full Administrator-powered user). For the moment, I have tries using the Start() static method of the...
1
3666
by: Fei Yuan | last post by:
Please forgive me re-posting this question since I wasn't clear in my original post. --------> Starting an external process needs to pass it a ProcessStartInfo() object. ProcessStartInfo has a property "UseShellExecute" that can open/print a file. For example, here's a piece of code that launches an external process to open a Microsoft Word Document: Process p = new Process();
4
2351
by: Chad Crowder | last post by:
I've taken a look at this article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspnet/html/asp12282000.asp which someone posted a month or so ago regarding setting up SQL server to handle state data. The article references .Net beta, and the file state.sql in the framwork/1.0x directory, but that file doesn't exist for version 1.1.4322. I'm wondering if there's a component that I need to install, or if I need to...
5
8731
by: ZWeng | last post by:
I created a windows service using FileSystemWatcher to moniter a folder for file drops. The service uses FileStream and StreamReader to read and process the file. After it is done, the file is copied to a different location and deleted in the original folder. If files coming in in short intervals (under sub-second) on XP OS, there is an error occured occassionally with the follow message: System.IO.IOException: The process cannot...
1
19990
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
0
9847
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
11282
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...
1
10983
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
9684
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8048
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7206
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();...
0
5894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4726
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
4308
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.