473,405 Members | 2,421 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,405 software developers and data experts.

File access

Hello!

I am trying to use a StreamReader to read a file that is in use, but get an
error message that the file is being used by another process.
It is nothing strange with the error message, cause the file is in use, but
when using Notepad, I can read the file, so I think there should be a way to
do this from .Net code as well?!?!

Any ideas?
/Magnus
Jul 21 '05 #1
4 1208
If you open the file using FileStream.Open instead of using StreamReader, you
can specify how to share the file with other users of the file (using the
FileShare enumeration). If you still want to use StreamReader, you can
create a StreamReader from the FileStream returned by FileStream.Open.

HTH, Jakob.
"Magnus Blomberg" wrote:
Hello!

I am trying to use a StreamReader to read a file that is in use, but get an
error message that the file is being used by another process.
It is nothing strange with the error message, cause the file is in use, but
when using Notepad, I can read the file, so I think there should be a way to
do this from .Net code as well?!?!

Any ideas?
/Magnus

Jul 21 '05 #2
Hello!

Tanks for your answer. Unfortunately I get the same message using the
code row below:

FileStream fs = File.Open(myfile, FileMode.Open,
FileAccess.Read, FileShare.Read);

Any idea?

Regards Magnus

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3
Hey Magnus,

I tried opening the same file for reading (using Filestream) from several
processes using FileShare.Read without any problems. Are some of your
processes writing to the file or are all of them opening the file for reading
only using your line of code below? Are you getting an exception every time
you run your program or only sometimes?

Regards, Jakob.
http://www.dotninjas.dk

"Magnus Blomberg" wrote:
Hello!

Tanks for your answer. Unfortunately I get the same message using the
code row below:

FileStream fs = File.Open(myfile, FileMode.Open,
FileAccess.Read, FileShare.Read);

Any idea?

Regards Magnus

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #4
Hello!

I think I solved the problem by using:

StreamReader sr = new StreamReader(new FileStream(myFileName,
FileMode.Open, FileAccess.Read, FileShare.ReadWrite));

Best Regards Magnus

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #5

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

Similar topics

18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
2
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
3
by: Joe Costa | last post by:
I have written the following code to search for the right file depending on the startup file for "Client Access". The menu database that I made will load the correct config file specific for each...
4
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup)...
1
by: raydelex | last post by:
I am new to securing a database with logins. My questions is: I want only one database to use a new Workgroup file that I have created, not all the Access databases that I bring up under my...
11
by: sur | last post by:
Hello, My problem is that File.Exists works fine if my file is on my local drive but returns false if its on any other drive. I think that the issue is probably file permissions and so I have...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
13
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...
16
by: Eran.Yasso | last post by:
Hi, I have a mdb file shared in the LAN. I want to write app that verifies if it's open. If the file is not open, then my app can open the file. if the file is used, then the app won't open it....
5
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello! I'm trying to copy a file from another computer on the network that I do not have permission with my current logon details to access. If I open the folder using the Windows file manager...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...

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.