473,729 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing a file, that another process has open..

Hi,

I have a situation where my application is trying to access a file, that
another application may have temporalily open.

The error I get is

The process cannot access the file 'C:\picks\test5 0k.gp1' because it is
being used by another process.
Is there a way I can loop in my program, some how testing if my app can
access the file, and then break out of the loop only when I can open the
file.

That way if another application has the file, I my app can wait till it is
finished.

Thanks

Aug 3 '08 #1
2 1580
You can catch the error with something like this

Try
' open the file
Catch ex As IOException
MsgBox(ex.Messa ge)
End Try

Instead of the MsgBox you can start a loop and a timer.. the timer is going
to check every 1 second if the file is still in use. When not, then you set
a variable that exits the loop

Hope this trick helps you

--
Windows Live Butterfly
My little blog - http://sunco.codigoplus.com (in Spanish)

"Newbie" <ne****@nospam. comescribió en el mensaje de
noticias:Os**** **********@TK2M SFTNGP03.phx.gb l...
Hi,

I have a situation where my application is trying to access a file, that
another application may have temporalily open.

The error I get is

The process cannot access the file 'C:\picks\test5 0k.gp1' because it is
being used by another process.
Is there a way I can loop in my program, some how testing if my app can
access the file, and then break out of the loop only when I can open the
file.

That way if another application has the file, I my app can wait till it is
finished.

Thanks
Aug 4 '08 #2
On Aug 3, 12:31 am, "Newbie" <new...@nospam. comwrote:
I have a situation where my application is trying to access a file, that
another application may have temporalily open.

The error I get is

The process cannot access the file 'C:\picks\test5 0k.gp1' because it is
being used by another process.
What code did you use to try to open the file? Did you specify a
sharing mode? If the other program has not opened the file
exclusively then you should be able to open the file at the same
time. Do you intend to modify the file? Or just read it? Some more
details would make it easier to help you.

Chris
Aug 5 '08 #3

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

Similar topics

6
7325
by: Pekka Niiranen | last post by:
Hi, I have used the following example from win32 extensions: -----SCRIPT STARTS---- import win32file import win32con import win32security import pywintypes
3
34524
by: trellow | last post by:
Hello, I am writing an application that needs to read a file that is already open by another process for writing. When I do the following: FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); I get the following exception:
6
5166
by: Ana | last post by:
Hi! I have problems with the following scenario: My application is developed using C# under .NET. It must run on all Windows versions starting from Windows 98. The user must open different documents (txt, MS Office files, pdf, pictures,…) from inside my app. It must start the file with the adequate external program (Notepad, MS Office programs, Acrobat Reader, some Picture viewer,... ) and be notified when this programs closes the...
2
1813
by: DanB | last post by:
I am using VB DotNet Std Edition and am writing a web application that needs to read and write to an password protected database. The mdb files reside in a folder (fpdb) under the localhost (c:\inetpub\wwroot) Within the IDE I can view the data using the server explorer and I use that same oledb connection for the web form. I have tried accessing a non-password protected db in the same folder using
0
1302
by: daniele.balducci | last post by:
Hi All, I'm experiencing troubles in a simple .net web application. The applicatione is made up by a single form looping to move some files to a different folder . the main loop is as follows : C Const CurrUploadDir= ..... Const CurrSentDir= ..... Dim CurFile as string CurFile = Dir(CurrUploadDir & "*.*")
13
11146
by: George | last post by:
Hi, I am re-writing part of my application using C#. This application starts another process which execute a "legacy" program. This legacy program writes to a log file and before it ends, it writes a specific string to the log file. My original program (MKS Toolkit shell program) which keeps running "grep" checking the "exit string" on the "log files". There are no file sharing problem.
9
5406
by: Carl | last post by:
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
2
1469
by: sushma | last post by:
Hi all. My Problem is i have an application that launches an external process on a button click. The other process has a feature of accessing a file during its load and also in its formclosing method. Now the problem is once i launch and close the application and immediately relaunch the application it gives me an exception saying that the file is in use. What is the workaround for this since same file is being accessed during the closing...
8
2180
by: colmkav | last post by:
Hi, could someone tell me how I can check whether a database is open by name eg something like db("mydbname")
0
8913
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
8761
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,...
0
9280
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
9200
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,...
1
6722
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
6016
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
4525
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
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2677
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.