473,669 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileStream question

I'm trying to open a file for writing in a server process. I do not want any
other process to be able to write to the file while I have it open, but I do
want to allow other programs to read from it. Seems simple enough. I've done
this with CFile in MFC. I'm getting a problem trying to use the .NET
FileStream class. I can open the files with other applications (notepad) and
they open up in 'readonly' mode which is what I expect. Can any of you shed
light on why I'm getting a 'File is in use' IO exception with this:

try
{
String Nm = "c:\\testfile.t xt";

//simulate the server opening the file for writing:
FileStream str = File.Open(Nm, FileMode.Append , FileAccess.Writ e,
FileShare.Read) ;

//simulate some other process opening the file for reading: (exception
thrown here)
FileStream sss = File.OpenRead(N m);
}
catch (IOException e)
{
System.Console. WriteLine(e.Mes sage);
}
thanks
Tim
Nov 15 '05 #1
0 1009

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

Similar topics

2
391
by: Kai Bohli | last post by:
Hi all ! This is my first day with Visual Studio and C#, and I'm trying to send "raw data" to the printer port. I found the SendFileToPrinter example below in a knowledge base at MS site It works, but I need to replace the filestream with a memorystream cause there's no need to write files and then load them again just to print. So I rewrote the procedure and the call. The problem is of course that it dosen't work. If I replace the...
9
5846
by: Tom | last post by:
I am working with the this object as oppose to the StreamReader object becuase I need to access a file (to find the contents) while an external application is updating the file. When I was working with the StreamReader object I got a deadlock when I tried reading the file while my external application was writing to it. So far I am able to create a FileStream object and open the file in question (CrawlerBackup.txt). But I am unable to...
5
12734
by: Chris Fink | last post by:
How do I load a string into a FileStream without going to disk? For example, string abc = "This is a string"; How do I load abc into a FileStream? FileStream input = new FileStream(.....);
0
1529
by: lh | last post by:
The following method only works when i give the ASP.net account full permissions on the directory. It doesn't work when i give the directory Modify, Read &Execute, List Folder Contents, Read, and Write permissions (all at the same time) I'm only trying to READ the file. Why do i have to give it full permissions? public static string ReadFileContents(string filePath) {
7
2300
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they...
2
1913
by: ewingate | last post by:
The following code which is supposed to dynamically create files with incrementing names is throwing an exception due to the inclusion of the DateTime.Now component of the sReportSave string: string sReportSave = ( DateTime.Now + "Report.Dat" ); FileStream fs = new FileStream( sReportSave , FileMode.Create ); Is my approach completely wrong or is there different way to modify the FileStream so that .NETclients used by multiple users...
0
331
by: dave | last post by:
my other Question: im Parsing data from a File.... should i be using string objects or stringbuilder i was reading about both of them and im looping through files upwards of 20meg to 100 meg of information The docs say sting class creates a new class each time it returns a substring or change in the string..... and Stringbuilder use its internal buffers Can you Explain a bit more about string builder which on i should use and the best...
2
4070
by: =?Utf-8?B?TWlzY2hh?= | last post by:
It is my understanding that I can create an XmlTextReader from a variety of sources, including a stream object. I am developing a web application that reads some data from an Xml file. Everything works fine if I use the XmlTextReader to open the file (i.e. pass it the file name): Dim reader As XmlTextReader = New XmlTextReader("<file_name>") But I get an access error if I try to open the file using a FileStream object and then passing...
7
1947
by: Piotrekk | last post by:
Hi Probability of this phenomena is like 1/200. The only code where I am dealing with file is the following: using (FileStream fs = new FileStream(this.FilePath, FileMode.Open,FileAccess.Read)) { try {
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
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
8809
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
8588
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
7407
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...
1
6210
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4206
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
2797
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
2
1788
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.