How can I detect if a file sitting on a network drive is still open by another
application?
This application resides on another machine on the network?
I am using VB.NET 2003
Your help is highly appreciated 6 3079
Try to open it, if you cant open it, it's still in use.
You could write a try catch around this and eventually write some loop to
test periodically if you can open it, and when you can, you could use the
file?
"Moumen VB.NET 2003/2005 Developer"
<Mo**************************@discussions.microsof t.com> wrote in message
news:1D**********************************@microsof t.com... How can I detect if a file sitting on a network drive is still open by another application?
This application resides on another machine on the network?
I am using VB.NET 2003
Your help is highly appreciated
Hi,
I tried your approach, but with no success.
Could you please post some code on how you can do it?
Thanks
"Joris De Groote" wrote: Try to open it, if you cant open it, it's still in use. You could write a try catch around this and eventually write some loop to test periodically if you can open it, and when you can, you could use the file?
"Moumen VB.NET 2003/2005 Developer" <Mo**************************@discussions.microsof t.com> wrote in message news:1D**********************************@microsof t.com... How can I detect if a file sitting on a network drive is still open by another application?
This application resides on another machine on the network?
I am using VB.NET 2003
Your help is highly appreciated
I would write something like:
' Precondition: the file "theFile" is known to exist
Public Function IsLocked(ByVal theFile As String) As Boolean
Dim theStream As FileStream
Dim theResult As Boolean
Try
' To test if the file is locked, it is enough just to try and open
it and handle
' any (resulting) exception. If an exception is raised, then the
file is locked.
theStream = New FileStream(theFile, FileMode.Open, FileAccess.Write)
' Success
theResult = False
Catch ex As IOException
' We failed to open it for writing, so it's probably locked.
theResult = True
Finally
If Not theStream Is Nothing Then
theStream.Close()
End If
End Try
Return theResult
End Function
"Moumen VB.NET 2003/2005 Developer"
<Mo**************************@discussions.microsof t.com> wrote in message
news:8F**********************************@microsof t.com... Hi,
I tried your approach, but with no success.
Could you please post some code on how you can do it?
Thanks
"Joris De Groote" wrote:
Try to open it, if you cant open it, it's still in use. You could write a try catch around this and eventually write some loop to test periodically if you can open it, and when you can, you could use the file?
"Moumen VB.NET 2003/2005 Developer" <Mo**************************@discussions.microsof t.com> wrote in message news:1D**********************************@microsof t.com... > How can I detect if a file sitting on a network drive is still open by > another > application? > > This application resides on another machine on the network? > > I am using VB.NET 2003 > > Your help is highly appreciated >
Yep
And if you want to wait until you want to open it, you can stil write a
while loop around it and keep trying until theResult = false .
Greetz
"Robin Mark Tucker" <ro*************@removehotmail.comremove> wrote in
message news:e5*******************@news.demon.co.uk... I would write something like:
' Precondition: the file "theFile" is known to exist
Public Function IsLocked(ByVal theFile As String) As Boolean
Dim theStream As FileStream Dim theResult As Boolean
Try
' To test if the file is locked, it is enough just to try and open it and handle ' any (resulting) exception. If an exception is raised, then the file is locked.
theStream = New FileStream(theFile, FileMode.Open, FileAccess.Write)
' Success
theResult = False
Catch ex As IOException
' We failed to open it for writing, so it's probably locked.
theResult = True
Finally
If Not theStream Is Nothing Then theStream.Close() End If
End Try
Return theResult
End Function
"Moumen VB.NET 2003/2005 Developer" <Mo**************************@discussions.microsof t.com> wrote in message news:8F**********************************@microsof t.com... Hi,
I tried your approach, but with no success.
Could you please post some code on how you can do it?
Thanks
"Joris De Groote" wrote:
Try to open it, if you cant open it, it's still in use. You could write a try catch around this and eventually write some loop to test periodically if you can open it, and when you can, you could use the file?
"Moumen VB.NET 2003/2005 Developer" <Mo**************************@discussions.microsof t.com> wrote in message news:1D**********************************@microsof t.com... > How can I detect if a file sitting on a network drive is still open by > another > application? > > This application resides on another machine on the network? > > I am using VB.NET 2003 > > Your help is highly appreciated >
Joris & Robin,
Thank you very much for your valuable replies.
However, I noticed that when I try to open a text file through NotePad.exe,
my program cannot detect that the file is open for writing by NotePad. On the
other hand, if I open the same text file with MS-Word, my program works
perfectly.
I would like my program to work with any application that tries to open the
network file.
Do you know why this happening only with NotePad?
Thanks!
"Joris De Groote" wrote: Yep
And if you want to wait until you want to open it, you can stil write a while loop around it and keep trying until theResult = false .
Greetz
"Robin Mark Tucker" <ro*************@removehotmail.comremove> wrote in message news:e5*******************@news.demon.co.uk...I would write something like:
' Precondition: the file "theFile" is known to exist
Public Function IsLocked(ByVal theFile As String) As Boolean
Dim theStream As FileStream Dim theResult As Boolean
Try
' To test if the file is locked, it is enough just to try and open it and handle ' any (resulting) exception. If an exception is raised, then the file is locked.
theStream = New FileStream(theFile, FileMode.Open, FileAccess.Write)
' Success
theResult = False
Catch ex As IOException
' We failed to open it for writing, so it's probably locked.
theResult = True
Finally
If Not theStream Is Nothing Then theStream.Close() End If
End Try
Return theResult
End Function
"Moumen VB.NET 2003/2005 Developer" <Mo**************************@discussions.microsof t.com> wrote in message news:8F**********************************@microsof t.com... Hi,
I tried your approach, but with no success.
Could you please post some code on how you can do it?
Thanks
"Joris De Groote" wrote:
Try to open it, if you cant open it, it's still in use. You could write a try catch around this and eventually write some loop to test periodically if you can open it, and when you can, you could use the file?
"Moumen VB.NET 2003/2005 Developer" <Mo**************************@discussions.microsof t.com> wrote in message news:1D**********************************@microsof t.com... > How can I detect if a file sitting on a network drive is still open by > another > application? > > This application resides on another machine on the network? > > I am using VB.NET 2003 > > Your help is highly appreciated >
I don't know this for sure (but this is what I think)
I don't think Notepad locks a file (since its pretty much a very basic
program), MS-Word does.
Joris
"Moumen VB.NET 2003/2005 Developer"
<Mo**************************@discussions.microsof t.com> wrote in message
news:B1**********************************@microsof t.com... Joris & Robin,
Thank you very much for your valuable replies.
However, I noticed that when I try to open a text file through NotePad.exe, my program cannot detect that the file is open for writing by NotePad. On the other hand, if I open the same text file with MS-Word, my program works perfectly.
I would like my program to work with any application that tries to open the network file.
Do you know why this happening only with NotePad?
Thanks!
"Joris De Groote" wrote:
Yep
And if you want to wait until you want to open it, you can stil write a while loop around it and keep trying until theResult = false .
Greetz
"Robin Mark Tucker" <ro*************@removehotmail.comremove> wrote in message news:e5*******************@news.demon.co.uk... >I would write something like: > > > ' Precondition: the file "theFile" is known to exist > > Public Function IsLocked(ByVal theFile As String) As Boolean > > Dim theStream As FileStream > Dim theResult As Boolean > > Try > > ' To test if the file is locked, it is enough just to try and > open > it and handle > ' any (resulting) exception. If an exception is raised, then the > file is locked. > > theStream = New FileStream(theFile, FileMode.Open, > FileAccess.Write) > > ' Success > > theResult = False > > Catch ex As IOException > > ' We failed to open it for writing, so it's probably locked. > > theResult = True > > Finally > > If Not theStream Is Nothing Then > theStream.Close() > End If > > End Try > > Return theResult > > End Function > > > > > > "Moumen VB.NET 2003/2005 Developer" > <Mo**************************@discussions.microsof t.com> wrote in > message > news:8F**********************************@microsof t.com... >> Hi, >> >> I tried your approach, but with no success. >> >> Could you please post some code on how you can do it? >> >> Thanks >> >> >> "Joris De Groote" wrote: >> >>> Try to open it, if you cant open it, it's still in use. >>> You could write a try catch around this and eventually write some >>> loop >>> to >>> test periodically if you can open it, and when you can, you could use >>> the >>> file? >>> >>> >>> "Moumen VB.NET 2003/2005 Developer" >>> <Mo**************************@discussions.microsof t.com> wrote in >>> message >>> news:1D**********************************@microsof t.com... >>> > How can I detect if a file sitting on a network drive is still open >>> > by >>> > another >>> > application? >>> > >>> > This application resides on another machine on the network? >>> > >>> > I am using VB.NET 2003 >>> > >>> > Your help is highly appreciated >>> > >>> >>> >>> > > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John |
last post by:
Hello,
I need to know which programs are opn on another machine in my network,
these programs are opened from a shared drive on the server. How can I do
this ? I've already dowloaded a sample...
|
by: o'seally |
last post by:
solaris/linux admins/rookie_developers that battle with this error are
probably all frustrated when it happens. i bet you're also somehow
frustrated by this seemingly unsolvable error :-) ...take...
|
by: moonriver |
last post by:
I write a program accessing files in network drive o:. It is doable as a standalone application. However, if it is running under windows service, the following exception will appear:
13/07/2004...
|
by: Daniel |
last post by:
Is this a bug in .net file io? is there a work around?
when writing a large file with using(StreamWriter ... if the network drive
of the share is removed then the file is never closed. I tried...
|
by: Lam |
last post by:
HI
anyone knows how can I open a mapped network file in C#?
I try string file = @"T:\file.txt"; it shows me the error: "Could not find
a part of the path"
but if I copy the file to my C dirve,...
|
by: Sarah |
last post by:
I need to access some data on a server. I can access it directly using UNC
(i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network
drive resource (S:\Path\FileName).
Here is my...
|
by: createdbyx |
last post by:
I am trying to make a file sync utillity to sync files between my
laptop and my desktop pc. On my desktop machine (xp pro sp2) I have
shared my "Visual Studio Projects" folder using windows simple...
|
by: Peter S. |
last post by:
I have an ASP.NET page that invokes a web control written in C#. What I want
to do is (based on the session ID) display a certain spreadsheet that exists
on a
network drive. I want the webcontrol...
|
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= |
last post by:
Hello!
I'm trying to copy a file from another computer on the network that I do not
have permission with my current logon details to access.
If I open the folder using the Windows file manager...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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: 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...
| |