How to open a file for read that is already open by another application 
Author Message
 How to open a file for read that is already open by another application

In VB6, that was easy using the OPEN statement! e.g.

Open Filename For Binary As #hLoadFile
or
Open Filename For Input As #hLoadFile

will open any file in any version of Windows regardless of the state
of the file i.e. even if another application had opened the file and
was still using it.

In VB.Net I get an IOException stating "The process cannot access the
file because the file is in use by another application" - I am opening
the file as follows (having tried almost every other variant of file
stream)

 Dim fIn As System.IO.FileStream = New
System.IO.FileStream(SourceFile, System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.Read, TotalBytes * 100)

I hoped that stating read access and shared read would work but it
does not make any difference.

Regards
Ian



Mon, 05 Jan 2004 04:45:11 GMT  
 How to open a file for read that is already open by another application
you could try using the vb6 compatability set of file commands.
Imports VB = Microsoft.VisualBasic

Imports Microsoft.VisualBasic.Compatibility

then you will use
vb6.Open(nfilenumber, "filename", VB6.OpenMode.Input, VB6.OpenAccess.Read,
VB6.OpenShare.Default) (or similar)

etc. all the old file commands are now methods starting with
vb6.

try them...

robin


Quote:
> In VB6, that was easy using the OPEN statement! e.g.

> Open Filename For Binary As #hLoadFile
> or
> Open Filename For Input As #hLoadFile

> will open any file in any version of Windows regardless of the state
> of the file i.e. even if another application had opened the file and
> was still using it.

> In VB.Net I get an IOException stating "The process cannot access the
> file because the file is in use by another application" - I am opening
> the file as follows (having tried almost every other variant of file
> stream)

>  Dim fIn As System.IO.FileStream = New
> System.IO.FileStream(SourceFile, System.IO.FileMode.Open,
> System.IO.FileAccess.Read, System.IO.FileShare.Read, TotalBytes * 100)

> I hoped that stating read access and shared read would work but it
> does not make any difference.

> Regards
> Ian



Mon, 05 Jan 2004 21:26:53 GMT  
 How to open a file for read that is already open by another application
How did you set the FileShare property in the "other application"?
Remember, this property determines the kind of access OTHER FileStreams can have to the same file.

Willy.

Quote:

> In VB6, that was easy using the OPEN statement! e.g.

> Open Filename For Binary As #hLoadFile
> or
> Open Filename For Input As #hLoadFile

> will open any file in any version of Windows regardless of the state
> of the file i.e. even if another application had opened the file and
> was still using it.

> In VB.Net I get an IOException stating "The process cannot access the
> file because the file is in use by another application" - I am opening
> the file as follows (having tried almost every other variant of file
> stream)

>  Dim fIn As System.IO.FileStream = New
> System.IO.FileStream(SourceFile, System.IO.FileMode.Open,
> System.IO.FileAccess.Read, System.IO.FileShare.Read, TotalBytes * 100)

> I hoped that stating read access and shared read would work but it
> does not make any difference.

> Regards
> Ian



Tue, 06 Jan 2004 03:39:52 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ShellExecute only opens file.htm if browser already open

2. Open an already opened file

3. Reading/deleting in a shared textfile (error 55: File already open)

4. Reading/deleting in a shared textfile (error 55: File already open)

5. How can i block opening a form that is already open

6. Mail merge from Access try to open an already open DB

7. Open a file in an opened application

8. File not Found / File already open

9. closing an application already opened with VBA 6 ??

10. closing an application already opened with VBA 6 ??

11. checking if a file is already open

12. Word cannot save this file because it is already open elsewhere

 

 
Powered by phpBB® Forum Software