473,695 Members | 2,914 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File sitting on a network drive is still open by another applicati

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

Jun 1 '06 #1
6 3100
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.mic rosoft.com> wrote in message
news:1D******** *************** ***********@mic rosoft.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

Jun 1 '06 #2
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.mic rosoft.com> wrote in message
news:1D******** *************** ***********@mic rosoft.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


Jun 1 '06 #3
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(theF ile, FileMode.Open, FileAccess.Writ e)

' 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.mic rosoft.com> wrote in message
news:8F******** *************** ***********@mic rosoft.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.mic rosoft.com> wrote in message
news:1D******** *************** ***********@mic rosoft.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
>


Jun 1 '06 #4
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******** ***********@new s.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(theF ile, FileMode.Open,
FileAccess.Writ e)

' 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.mic rosoft.com> wrote in message
news:8F******** *************** ***********@mic rosoft.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.mic rosoft.com> wrote in
message
news:1D******** *************** ***********@mic rosoft.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
>


Jun 2 '06 #5

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******** ***********@new s.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(theF ile, FileMode.Open,
FileAccess.Writ e)

' 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.mic rosoft.com> wrote in message
news:8F******** *************** ***********@mic rosoft.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.mic rosoft.com> wrote in
message
news:1D******** *************** ***********@mic rosoft.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
>



Jun 2 '06 #6
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.mic rosoft.com> wrote in message
news:B1******** *************** ***********@mic rosoft.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******** ***********@new s.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(theF ile, FileMode.Open,
> FileAccess.Writ e)
>
> ' 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.mic rosoft.com> wrote in
> message
> news:8F******** *************** ***********@mic rosoft.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.mic rosoft.com> wrote in
>>> message
>>> news:1D******** *************** ***********@mic rosoft.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
>>> >
>>>
>>>
>>>
>
>


Jun 6 '06 #7

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

Similar topics

3
2751
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 program form vbnet.mvps.org but it doesn't work?? Greets John
6
16639
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 it easy, it'll go away once u've learned how to play around with a few things on your system and reorganised. i'm particulary a solaris junkie, but linux is my admiration. the issue here is Not the OS/Software, but rather the concept. first of all...
6
9714
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 10:24:48 AM run() error: System.IO.IOException: The specified network password is not correct. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare...
0
1308
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 doing the using clause, i tried both close and closehandle in the finaly clause. in all cases if a large file is being written to a network drive and the network drive is disconnected the file handle remains open. when i try to close, dispose, or...
8
11845
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, and use @"C:\file.txt"; it worked Thanks a lot
8
9752
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 problem: my vb.net program has problems with UNC. If the UNC server is restarted or goes off-line, my VB.net program crashes. The code for UNC access to the file is included below and is put in the tick event of a form timer control running every...
2
4748
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 file sharing. And have specified the "Allow network users to change my files." option as well. Then on my laptop (xp home sp2) I have mapped a network drive using windows explorer. So on my laptop I have a Y: drive that points to the "Visual...
2
4154
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 to open the spreadsheet using my log on credentials since they won't have priviliges to access their particular file from the network drive. BTW, I am guessing I will have to use HTTP as this file exists in a Sharepoint document library. I can...
5
17749
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 with the path "\\ 192.168.2.2\temp" (where temp is a shared directory on server \\192.168.2.2), windows prompts for a User Name and password of a user who has permission on that computer to access that directory. If I enter valid details, the...
0
9112
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
8975
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
8826
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
8818
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
7652
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
6487
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
4338
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...
0
4575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.