473,395 Members | 1,915 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,395 software developers and data experts.

Check if a file is allready open by other application

Hello NG !
I would like to test, if a file in my subtree is allready in use by an other
application.
Do anybody know how to get this information ? It is possible to get this
information ?

Thanks and regards.

Marcel Hug
Nov 16 '05 #1
4 29423
try
{
using(FileStream fs = File.OpenWrite(strFileName)
{
if(fs == null)
return;
}
}
catch(UnauthorizedAccessException e)
{
//Here you know that the file is open by another app
}

"Marcel Hug" <ma**********@ch.abbdotcom> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
Hello NG !
I would like to test, if a file in my subtree is allready in use by an
other
application.
Do anybody know how to get this information ? It is possible to get this
information ?

Thanks and regards.

Marcel Hug

Nov 16 '05 #2
On Thu, 20 Jan 2005 12:04:46 +0100, Marcel Hug wrote:
Hello NG !
I would like to test, if a file in my subtree is allready in use by an other
application.
Do anybody know how to get this information ? It is possible to get this
information ?

Thanks and regards.

Marcel Hug


Try to open the file exclusively. If that files, then something else is
using the file. Ex:

FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read,
FileShare.None);

Make sure to add proper exception handling around that and code to close
the file so it doesn't remain locked.
--
Tom Porterfield
Nov 16 '05 #3
Hi,

It's possible but doing so is complex , I know if only one program (
ProcessExplorer ) that does it, no idea how though :(

The best you can do is trying to open the file with no sharing and catch the
exception if this fail, not the best way but it works
use this code

bool opened;
try{

FileStream fs = new FileStream( file, FileMode.Open, FileAccess.Write,
FileShare.None);
fs.Close();
opened = false;
}
catch( FileNotFoundException ex)
{
//what to do now?
opened = false;
}
catch( UnauthorizedAccessException e)
{
opened = true;
}
If you are 100% sure the file exist remove the first catch block
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Marcel Hug" <ma**********@ch.abbdotcom> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
Hello NG !
I would like to test, if a file in my subtree is allready in use by an
other
application.
Do anybody know how to get this information ? It is possible to get this
information ?

Thanks and regards.

Marcel Hug

Nov 16 '05 #4
Hi,

OpenWrite create the file if it's not exist, maybe this is not the
intention. but only to test if the file exist and is open.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Yitzhak Gootvilig" <Go*******@gmail.com> wrote in message
news:uo**************@TK2MSFTNGP09.phx.gbl...
try
{
using(FileStream fs = File.OpenWrite(strFileName)
{
if(fs == null)
return;
}
}
catch(UnauthorizedAccessException e)
{
//Here you know that the file is open by another app
}

"Marcel Hug" <ma**********@ch.abbdotcom> wrote in message
news:eK**************@TK2MSFTNGP14.phx.gbl...
Hello NG !
I would like to test, if a file in my subtree is allready in use by an
other
application.
Do anybody know how to get this information ? It is possible to get this
information ?

Thanks and regards.

Marcel Hug


Nov 16 '05 #5

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

Similar topics

10
by: Raymond | last post by:
Hi All: To find a file exists using the file name, I have tow routings on UNIX system. 1. access(2) 2. lstat(2) This tow function also can do. When the return value is "-1" and errno is...
6
by: Jesper. | last post by:
Know of any good tutorials to demonstrate how to assign a file extension to an applicatiand and how to open the file in the application when you doubleclick on the file in the OS brgds Jesper.
2
by: Michael Sutherland | last post by:
I'm attempting to use a Hyperlink within a database to open an outside Acrobat or Word file. I've placed the path into the database, and I've accessed the path in my program via the normal...
6
by: Dino Buljubasic | last post by:
My application creates some temporary files that are deleted when my application terminates. However, if a temp file is open, it will not be deleted and application will crash. How can I...
4
by: Alex Simic | last post by:
Dear All, Is there a function in dotnet VB, which returns if a file is open or used by other process? Thanks, Alex
2
by: Ronald S. Cook | last post by:
I have a VB.NET Win app wherein I would like to (via code) open another application window external to my app's window and set the position and size on the user's screen. I would greatly...
1
by: sunil | last post by:
Hi all, I have a web application in which I have to open a "chm" file that exists on the local file system. I am able to open other files such as PDF, DOC files by writing the Response's output...
6
by: Ros | last post by:
There are 10 files in the folder. I wish to process all the files one by one. But if the files are open or some processing is going on them then I do not want to disturb that process. In that case...
5
by: carlos | last post by:
I need help in starting an open source application. What steps should I take in getting other developers in line with my idea without it getting stolen? How can I get other's involved? What is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.