How to get access to in use file? 
Author Message
 How to get access to in use file?

Hello,
I have added an item to the context menu of files so that
when a user right clicks on a file and selects my item,
it loads the program with the selected file in the
command line. The program then attempts to open the file,
write something to it, and close it. It never gets this
far however, as an IOException is thrown saying the file
is in use by another process. Is there a way around this?

Here is what it looks like:

Dim myStream As New FileStream(Path, FileMode.Open,
FileAccess.ReadWrite, FileShare.ReadWrite)

//here the System.IO.IOException is thrown

Thanks,

Mack D. Male



Mon, 27 Dec 2004 03:06:03 GMT  
 How to get access to in use file?
Hello Mack -

Could you send more information about your application, particularly where
the file list is coming from, the code you adding items to the context menu,
and how you are opening the file and using the FileStream? Are you adding to
the context menu in the Solution Explorer?

If you are opening the file using a FileStream and then also opening the
file with a program such as Notepad, then indeed the file is open by another
user (your application) and Notepad will not be able to make changes to the
file.

Robin and Mohan
VB Team

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Hello,
> I have added an item to the context menu of files so that
> when a user right clicks on a file and selects my item,
> it loads the program with the selected file in the
> command line. The program then attempts to open the file,
> write something to it, and close it. It never gets this
> far however, as an IOException is thrown saying the file
> is in use by another process. Is there a way around this?

> Here is what it looks like:

> Dim myStream As New FileStream(Path, FileMode.Open,
> FileAccess.ReadWrite, FileShare.ReadWrite)

> //here the System.IO.IOException is thrown

> Thanks,

> Mack D. Male



Mon, 27 Dec 2004 03:47:22 GMT  
 How to get access to in use file?

To add my item to the context menu, I have edited the
registry as follows:

HKCR\*\Shell\myItem = "myItem"
HKCR\*\Shell\myItem\command = "C:\My Visual Studio
Projects\myItem.exe" ~%1

Inside of myItem.exe, the command line is parsed. So if I
right-click on C:\test.txt and select "myItem", the
application launches and parses the command line to get a
string "C:\test.txt". At this point, Notepad is not open,
nor is any other application accessing the file. Only
applications open are My Computer (from within which I
right clicked on the file) and myItem.exe which has
parsed the command line.

Next, I take the string and attempt to open the file
using the following line:

Dim myStream As New FileStream(Path, FileMode.Open,
FileAccess.ReadWrite, FileShare.ReadWrite)

It is immediately after this line that a
System.IO.IOException is thrown as follows:

        System.IO.IOException: The process cannot access
the file "C:\test.txt" because it is being used by
another process.

Everything after the line where I declare myStream is not
executed, for example msgbox("Stream Created") never gets
processed because of the error.

So I am thinking that when my application tries to access
the file, it is coming up against the error because My
Computer is also using the file. Is this correct? And
regardless, how can I get around this?

Quote:
>-----Original Message-----
>Hello Mack -

>Could you send more information about your application,
particularly where
>the file list is coming from, the code you adding items

to the context menu,
Quote:
>and how you are opening the file and using the

FileStream? Are you adding to
Quote:
>the context menu in the Solution Explorer?

>If you are opening the file using a FileStream and then
also opening the
>file with a program such as Notepad, then indeed the

file is open by another
Quote:
>user (your application) and Notepad will not be able to
make changes to the
>file.

>Robin and Mohan
>VB Team

>--
>This posting is provided "AS IS" with no warranties, and
confers no rights.


>> Hello,
>> I have added an item to the context menu of files so
that
>> when a user right clicks on a file and selects my item,
>> it loads the program with the selected file in the
>> command line. The program then attempts to open the
file,
>> write something to it, and close it. It never gets this
>> far however, as an IOException is thrown saying the
file
>> is in use by another process. Is there a way around
this?

>> Here is what it looks like:

>> Dim myStream As New FileStream(Path, FileMode.Open,
>> FileAccess.ReadWrite, FileShare.ReadWrite)

>> //here the System.IO.IOException is thrown

>> Thanks,

>> Mack D. Male

>.



Mon, 27 Dec 2004 04:18:52 GMT  
 How to get access to in use file?
I have emailed more details to you. Thanks for the prompt
response.

Quote:
>-----Original Message-----
>Hello Mack -

>Could you send more information about your application,
particularly where
>the file list is coming from, the code you adding items

to the context menu,
Quote:
>and how you are opening the file and using the

FileStream? Are you adding to
Quote:
>the context menu in the Solution Explorer?

>If you are opening the file using a FileStream and then
also opening the
>file with a program such as Notepad, then indeed the

file is open by another
Quote:
>user (your application) and Notepad will not be able to
make changes to the
>file.

>Robin and Mohan
>VB Team

>--
>This posting is provided "AS IS" with no warranties, and
confers no rights.


>> Hello,
>> I have added an item to the context menu of files so
that
>> when a user right clicks on a file and selects my item,
>> it loads the program with the selected file in the
>> command line. The program then attempts to open the
file,
>> write something to it, and close it. It never gets this
>> far however, as an IOException is thrown saying the
file
>> is in use by another process. Is there a way around
this?

>> Here is what it looks like:

>> Dim myStream As New FileStream(Path, FileMode.Open,
>> FileAccess.ReadWrite, FileShare.ReadWrite)

>> //here the System.IO.IOException is thrown

>> Thanks,

>> Mack D. Male

>.



Mon, 27 Dec 2004 04:16:17 GMT  
 How to get access to in use file?
Sorry, we have tried the scenario and the file opens and writes ok with no
locking problem.  Can you send us more detailed code if you still have
problems?

Ting Liang -VB Dev Team
Luca Dellamore
--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:

> To add my item to the context menu, I have edited the
> registry as follows:

> HKCR\*\Shell\myItem = "myItem"
> HKCR\*\Shell\myItem\command = "C:\My Visual Studio
> Projects\myItem.exe" ~%1

> Inside of myItem.exe, the command line is parsed. So if I
> right-click on C:\test.txt and select "myItem", the
> application launches and parses the command line to get a
> string "C:\test.txt". At this point, Notepad is not open,
> nor is any other application accessing the file. Only
> applications open are My Computer (from within which I
> right clicked on the file) and myItem.exe which has
> parsed the command line.

> Next, I take the string and attempt to open the file
> using the following line:

> Dim myStream As New FileStream(Path, FileMode.Open,
> FileAccess.ReadWrite, FileShare.ReadWrite)

> It is immediately after this line that a
> System.IO.IOException is thrown as follows:

> System.IO.IOException: The process cannot access
> the file "C:\test.txt" because it is being used by
> another process.

> Everything after the line where I declare myStream is not
> executed, for example msgbox("Stream Created") never gets
> processed because of the error.

> So I am thinking that when my application tries to access
> the file, it is coming up against the error because My
> Computer is also using the file. Is this correct? And
> regardless, how can I get around this?

> >-----Original Message-----
> >Hello Mack -

> >Could you send more information about your application,
> particularly where
> >the file list is coming from, the code you adding items
> to the context menu,
> >and how you are opening the file and using the
> FileStream? Are you adding to
> >the context menu in the Solution Explorer?

> >If you are opening the file using a FileStream and then
> also opening the
> >file with a program such as Notepad, then indeed the
> file is open by another
> >user (your application) and Notepad will not be able to
> make changes to the
> >file.

> >Robin and Mohan
> >VB Team

> >--
> >This posting is provided "AS IS" with no warranties, and
> confers no rights.


> >> Hello,
> >> I have added an item to the context menu of files so
> that
> >> when a user right clicks on a file and selects my item,
> >> it loads the program with the selected file in the
> >> command line. The program then attempts to open the
> file,
> >> write something to it, and close it. It never gets this
> >> far however, as an IOException is thrown saying the
> file
> >> is in use by another process. Is there a way around
> this?

> >> Here is what it looks like:

> >> Dim myStream As New FileStream(Path, FileMode.Open,
> >> FileAccess.ReadWrite, FileShare.ReadWrite)

> >> //here the System.IO.IOException is thrown

> >> Thanks,

> >> Mack D. Male

> >.



Mon, 03 Jan 2005 03:47:14 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Getting file info using a file list box and putting in an array

2. Getting Local Drive Label Using Access V2

3. Getting Data from Registry using Access 2

4. Getting data from security-enabled Access 2 to Excel 7 using DAO

5. getting access to outlook 200 address book using vb.net

6. Getting list of reports and printing from Access DB using VB

7. Question on getting my program using Web browser to access

8. Getting a picture stored in access using DAO or RDO

9. Getting List of Stored Queries in Access using ADO

10. From: Getting a picture stored in access using DAO or RDO

11. Getting the space used by a folder and files contained

12. Getting a File Version using VBScript

 

 
Powered by phpBB® Forum Software