473,395 Members | 2,006 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.

IO locked error

When a user has a file open and of course .NET cant access it due to it
being locked i get an error back like this through an exception

System.IO.IOException: The process cannot access the file 'S:\Care.xls'
because it is being used by another process.

is there any way to trap that specific error and give a user friendly
message back? but on any other errors throw an exception? thanks!
Jan 13 '06 #1
4 916
"Brian Henry" <no****@nospam.com> schrieb
When a user has a file open and of course .NET cant access it due to
it being locked i get an error back like this through an exception

System.IO.IOException: The process cannot access the file
'S:\Care.xls' because it is being used by another process.

is there any way to trap that specific error and give a user
friendly message back? but on any other errors throw an exception?
thanks!

try
'code
catch ex as System.IO.IOException
'user friendly message
end try
Armin

Jan 13 '06 #2
That traps all IO errors though... I just want something when the file is
locked to say something like "You already have this file open, please close
it and try agian" before you could do this with error codes, with exceptions
you dont seem to have them anymore that I know of

I still want IO errors like file not found and stuff to throw exceptions
outside of the one i already mentioned
Jan 13 '06 #3
Brian,

You could examine the exception's Message property. But that runs the risk
that the message could change in future versions of the framework.

Kerry Moorman
"Brian Henry" wrote:
That traps all IO errors though... I just want something when the file is
locked to say something like "You already have this file open, please close
it and try agian" before you could do this with error codes, with exceptions
you dont seem to have them anymore that I know of

I still want IO errors like file not found and stuff to throw exceptions
outside of the one i already mentioned

Jan 13 '06 #4
"Brian Henry" <no****@nospam.com> schrieb
That traps all IO errors though... I just want something when the
file is locked to say something like "You already have this file
open, please close it and try agian" before you could do this with
error codes, with exceptions you dont seem to have them anymore that
I know of

I still want IO errors like file not found and stuff to throw
exceptions outside of the one i already mentioned


You wrote that you want to catch only IOException, not all other exceptions.
That's what the example does.

You could rethrow the exception if it's one of the exceptions derived from
IOException: (untested)

try
'code
catch ex as ioexception
if ex.gettype is gettype(ioexception) then
'message here
else
throw
end if
end try
Another way:
const ERROR_SHARING_VIOLATION as integer = 32

try
'code
Catch ex As IOException When
System.Runtime.InteropServices.Marshal.GetLastWin3 2Error =
ERROR_SHARING_VIOLATION
'message
end try
However, I'm not sure whether error #32 is the only error that indicates a
sharing violation.
Armin

Jan 13 '06 #5

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

Similar topics

1
by: Rolan | last post by:
Having tried various permutations of Before Update and well for that matter, After Update, OnExit, OnEnter, etc. and also Locked controls, I'm still unable to obtain the intended results. There are...
2
by: Vinny Vinn | last post by:
On occasion a Network User Account gets locked out. This causes lots of problems as the account is used to run different programs. The programs fail when the user account is locked out. I would...
4
by: hkappleorange | last post by:
I ued this code to connect to a mdb file A = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\Inetpub\wwwroot\ASPX\Authors.mdb" )
10
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in...
0
by: Tommy B | last post by:
I'm currently working on a casino script for an IRC bot. I was going to make a flat file database, but I decided to make it sqlite after some suggestions. I'm using pysqlite. ...
5
by: cmay | last post by:
The only examples I have seen on how to check if a file is locked is to try to open it a catch an exception. MS has stated that you should never use error trapping in this manner. Is there no...
6
by: elake | last post by:
I found this thread about a pst file in Windows being locked and I am having the same issue. ...
0
by: Access Programming only with macros, no code | last post by:
ERROR MESSAGE: Could not update; currently locked by another session on this machine. BACKGROUND I have the following objects: Table1 - HO (which has about 51,000+ records) Table2 -...
6
by: ljstern | last post by:
Hello. I am using MS Access 2003 with XP/pro. I have a form that has the following properties set through the property sheet: form: AllowAdditions = False CartridgeID field: Locked = True ...
11
by: fniles | last post by:
One of our application uses VB6 and Access97 database. Another application uses VB.NET 2005. This morning for about 15 seconds when the application tries to read either a query or a table from the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
0
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...
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.