473,386 Members | 1,860 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,386 software developers and data experts.

Need shared access to file in C and C#

In C, I'm creating a log file like this:

upd = _fsopen(outputFile, "wt", _SH_DENYNO));

// writing... Here's a sample.
fprintf(upd, "Sample contents");

fclose(upd);
In another thread -- in the same process -- I'm attempting to open this
file with:

FileStream fs = new FileStream(convertFile, FileMode.Open,
FileAccess.Read, FileShare.Read);

Which is throwing:

The process cannot access the file '[your file here]' because it is
being used by another process.
A first chance exception of type 'System.IO.IOException' occurred in
mscorlib.dll

As far as I can tell, I'm doing everything right. In the C code, I'm
leaving the file as open for sharing as I possibly can, and in the C#
I'm opening it with the right flags.

Nov 28 '06 #1
2 10770
<cl****@gmail.comwrote in message
news:11********************@l12g2000cwl.googlegrou ps.com...
In C, I'm creating a log file like this:

upd = _fsopen(outputFile, "wt", _SH_DENYNO));

// writing... Here's a sample.
fprintf(upd, "Sample contents");

fclose(upd);
In another thread -- in the same process -- I'm attempting to open this
file with:

FileStream fs = new FileStream(convertFile, FileMode.Open,
FileAccess.Read, FileShare.Read);

Which is throwing:

The process cannot access the file '[your file here]' because it is
being used by another process.
A first chance exception of type 'System.IO.IOException' occurred in
mscorlib.dll

As far as I can tell, I'm doing everything right. In the C code, I'm
leaving the file as open for sharing as I possibly can, and in the C#
I'm opening it with the right flags.

No, you don't. You are trying to open the file in shared read mode (FileShare.Read), which
isn't possible as the file is already open in shared read/write mode, so, you need to share
the file for read/write too.

Willy.

Nov 28 '06 #2
cl****@gmail.com wrote:
FileStream fs = new FileStream(convertFile, FileMode.Open,
FileAccess.Read, FileShare.Read);

As far as I can tell, I'm doing everything right. In the C code, I'm
leaving the file as open for sharing as I possibly can, and in the C#
I'm opening it with the right flags.
Following up on my own post. The problem is, of course, that the:

FileShare.Read

Should have been:

FileShare.ReadWrite
...

D'oh.

Nov 28 '06 #3

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

Similar topics

2
by: Douglass Turner | last post by:
Hi, Please release me from my own private hell. Platform: SuSE 8.1 I'm installing python 2.3 tarball as follows: ../configure --enable-shared make
6
by: Ernesto | last post by:
I'm in the process of moving a Python application from Windows to Linux. This means that the drivers for windows ".dll" now must be Linux drivers "shared library file" (.so I think). With...
5
by: DeanL | last post by:
Hi all, I'm having a few problems with a shared access 97 db. I have the database split with the tables on the server and everything else in "client" front ends with links to the tables, e.g....
3
by: gmax2006 | last post by:
Hi, I am using RedHat Linux 4. and I developed an oracle 10g based application by using cx_Oracle (cx_Oracle-4.1-10g-py23-1.i386.rpm) and Python 2.3.4. When I run the application through...
13
by: Elton Cohen | last post by:
Hi newsgroup! Can anyone tell me where I should put a simple Access database file in order to be accessible for every computer in the network (same workgroup)? There does not need to be any...
1
by: vasilip | last post by:
root@Server:/opt/ibm/db2/V9.1/bin# ./db2adutl ../db2adutl: error while loading shared libraries: libApiDS.so: cannot open shared object file: No such file or directory I just installed db2 9.1...
4
by: Randoz | last post by:
I have a shared access program is a shared directory on a server. I have put no restictions are set up anything different than the defaults. Some indivduals are not having any problem at all and...
3
by: limperger | last post by:
Hello! This is quite important. We have an Access file shared in a network. Every user has its front-end copy that is linked to a back-end copy. This database has an autonumber field to count...
3
by: Rams chin | last post by:
Hi, Iam trying to build crda agent module on a cross platform(ARM). To build the same, one of the input module is m2crypto shared object file. I have sucesfully cross compiled and m2crypto.so file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.