473,806 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BinaryReader got Exception error

I tried to open a binary file use BinaryReader.

BinaryReader binReader = new BinaryReader(Fi le.Open(fileNam e, FileMode.Open,
FileAccess.Read , FileShare.Read) );

This file is open by another process at the same time. An exception is
generated said "This file is being used by another process".

What should I do to open this file for read only and an exception error?
Nov 16 '05 #1
2 2170
What else has the file open? It may have it open with FileShare.None. If you
don't have control over the application that's already got the file open,
then you may not be able to open it.

Pete

"Yuki" <Yu**@discussio ns.microsoft.co m> wrote in message
news:78******** *************** ***********@mic rosoft.com...
I tried to open a binary file use BinaryReader.

BinaryReader binReader = new BinaryReader(Fi le.Open(fileNam e, FileMode.Open, FileAccess.Read , FileShare.Read) );

This file is open by another process at the same time. An exception is
generated said "This file is being used by another process".

What should I do to open this file for read only and an exception error?

Nov 16 '05 #2
The file is open with CFile::shareDen yWrite flag from an C++ window applcation.
I can open this file for read by using MFC CFile, but not with C#
BinaryReader.

Angel
Nov 16 '05 #3

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

Similar topics

2
2447
by: Chris P. | last post by:
I have a C# application that connects to Perl application on a UNIX server. I am able to connect and communicate both directions with the server, but there are several occasions when it appears that the BinaryReader only reads part of the message sent by the server. Here is the main flow of my application. 1. Open Socket 2. Read 4 byte integer 3. Read byte array that is the size of the integer in step 2. 4. Put message in collection
0
2122
by: Denny Rue | last post by:
I’ve created VB code to download files from a web site through the use of HTTPWebRequest, HTTPWebResponse and BinaryReader. The HTTPWebRequest has a TimeOut property to limit how long it waits for a corresponding HTTPWebResponse. This works just fine. However, the timeout does not appear to apply to a BinaryReader created from the HTTPWebResponse. I’ve had instances where the procedures will hang indefinitely during the download. ...
4
1863
by: Robert Misiak | last post by:
I've been trying out the .NET Memory Profiler (http://www.scitech.se/memprofiler/) and I found an excessive number of undisposed instances of BinaryReader after opening and then closing various forms. The thing that these forms have in common is that they are localized for both English and Dutch. I tried adding resources.ReleaseAllResources() from the destructor but that had no effect. I'm pretty sure that it is the localization code...
2
23614
by: Bob Rock | last post by:
I already found an alternative way to accomplish this (using ReadBytes), still I'd like to understand why I'm getting and error reading a text file using the following method. The exception is returned on the ReadString call. public string BinaryRead(string fileName) { FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
6
4329
by: Question with BinaryReader | last post by:
I use BinaryReader to read my binary dafa files, when i call ReadBytes, why it always return more 4 bytes. The following is my code. FileStream fs = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Read); BinaryReader br = new BinaryReader(fs); Byte bytes = br.ReadBytes(8); bytes = br.ReadBytes(1); After the first sentence, fs.Position is 0, and all things is ok, but when runs to the second sentence, i found fs.Position is 4,...
1
3353
by: JimM | last post by:
I'm trying to read a file into a structure, called LogFile, but the compilier issues error message: error C2228: left of '.ReadBytes' must have class/struct/union typ Can anyone spot what is wrong with this declaration Thanks Ji int LoadLog(char * path
0
1088
by: Dave | last post by:
I'm reading chars from a file and displaying them in a label on a form. Following is a listing of the code section. Could anyone tell me the best way to do this? What I have works but wanted to know if there is a better way. I had some trouble converting the binaryreader->readchars so that they could be added to the label. Thanks for your help. Dave
5
7504
by: Tim | last post by:
Hi, I'm experiencing some problem with the following code: st = File.Open(sFilename, FileMode.Open, FileAccess.ReadWrite) br = New BinaryReader(st) Do Until br.PeekChar = -1 Dim buffer() As Byte = br.ReadBytes(1024) ...
3
4801
by: =?Utf-8?B?VmljdG9y?= | last post by:
Hi, Could you tell me can I keep the MemoryStream open and "close" the BinaryReader? As the MemoryStream is used for buffering the TCP data and BinaryReader is only used to read the MemoryStream, so I don't want to close the MemoryStream. Do I really need to close the BinaryReader if the underlying backing store needs not to be closed?
0
9719
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
10623
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10371
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
10373
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,...
0
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9192
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6877
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
5546
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...
1
4330
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 we have to send another system

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.