473,757 Members | 2,066 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 5406
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
7595
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
1592
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
2971
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
14422
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
3657
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
2344
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
8724
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
19953
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
9487
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
9297
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,...
1
9884
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
9735
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
8736
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 project—planning, coding, testing, and deployment—without 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
7285
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
6556
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
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3395
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.