473,473 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need expert's advice

PJ
Hi all,

I have two option to open a file stream

1. Dim mStream As Stream = New FileStream(localFile, FileMode.Open,
FileAccess.Read)

This works fine as long as the file is closed. If a file is being opened by
another process (even a .log or .txt file), it fails.

2. Dim mStream As Stream = File.Open(localFile, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite)

This works fine as long as the file is closed. However, if the file is .txt
or .log, it works fine EVEN IF the file is open (Failed when I used option
1)

My question is, can I use option 2 or I have to use option 1 for this? What
are the differences? Thanks. I use in my FTP class.
Nov 21 '05 #1
1 926
The difference is the FileShare parameter. In your first line you did
not allow sharing and you are basically saying:

"I want to open the file for Read access and I DONT want to allow
anyone else to open it or even access it"

Since another process has already opened the file, you cannot get
exclusive access to it so the call fails.

For the second you are saying this:

"I want to open the file for read access but I will allow other
processes to Read and Write to the file."

Since you allow the other process ReadWrite access, your call was
successful because you were not trying to get exclusive access to the
file. If the other process had opened the file exclusively, then your
call would still have failed.

Nov 21 '05 #2

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

Similar topics

7
by: John Smith | last post by:
Hi All, Sorry if I am calling expert's advice on such a simple thing. I am reading a c++ code but do not understand what this means? #define DM_ITEMS 6 #define FM_ITEMS ( 1 << (DM_ITEMS -...
0
by: Gary Stollman | last post by:
My Father is a Clone//ETs plotting to overthrow the human race! On August 19, 1987 a gun-carrying Gary Stollman entered the studio of Los Angeles's KNBC television, crashing consumer reporter...
15
by: Don Vaillancourt | last post by:
I do a lot of hiring for my company and a lot of the people I interview say that they are experts at SQL queries, but when I give them something simple just beyond the typical SELECT type of...
5
by: Kevin Carne | last post by:
First, Merry Christmas. I have been doing intensive Java programming for two years in school (no choice on the language), but now I need to return to C++ because my resume is filled with it both in...
3
by: apattin | last post by:
Hi all, I need some expert advice on a ROLLUP fine point. summary_table table has 4 columns: file_id primary_site morphology primary
1
by: Chris | last post by:
Hi, I am developing an app with the common layers APP,BLL and DAL. I am puzzled as to where I should put the DAL? I need the app to be distributed as possible as well as the DAL will be acceddes...
9
by: mistral | last post by:
Need help to remove list of days from date script. Need format "June 07, 2006" <SCRIPT LANGUAGE="JavaScript"> <!-- Begin // Get today's current date. var now = new Date();
3
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Hi, I am developing an app where customer post request via a website, the request, upon receipt by the office, must the be pushed to respective mobile PDAs.n The requests are sort of order pickup....
0
by: onegative | last post by:
G'day Y'all, I was hoping to get some expert feedback on a proposal I am considering regarding a new internal application to help fill some gaps in our IT department. I have some configuration...
7
by: SM | last post by:
Hello, I have a index.php template (2 columns). The right columns contains a bunch of links (interviews, poems, etc...) The left columns contains the actual article. So if I click on a link on...
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
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
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,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
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...

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.