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

Change File Content

Hi

I want to change the content of text file.
I use an StreamReader to read but I canīt use a StreamWriter for the same
Stream.

What I must do to implement content changing?

Thanks for help
Fabian
Nov 16 '05 #1
4 6294
Hi!

Since StreamReader is just for read and StreamWriter just for write try to
use the FileStream instead.

Anders

"Fabian" <fa***********@N-O-S-P-A-M.itacs.de> skrev i meddelandet
news:Og**************@TK2MSFTNGP14.phx.gbl...
Hi

I want to change the content of text file.
I use an StreamReader to read but I canīt use a StreamWriter for the same
Stream.

What I must do to implement content changing?

Thanks for help
Fabian

Nov 16 '05 #2
"Fabian" <fa***********@N-O-S-P-A-M.itacs.de> wrote in message
news:Og**************@TK2MSFTNGP14.phx.gbl...
Hi

I want to change the content of text file.
I use an StreamReader to read but I canīt use a StreamWriter for the same
Stream.

I would assume that you read the file, change the contents, file the changed
contents.
Then what is your problem?
Nov 16 '05 #3
Hi,

Writting the file that you are reading is fine ONLY IF you will no change
the size of it and you only write on the part that you read already,
otherwise you could overwrite the original content.
It's much better if you create a temp file, write to it and when done just
delete the original file and rename the temp file.

You can use Path.GetTempPath() to create the new file in
and Guid.NewValue() to name the file with an unique filename.

Something in the back of my head tells me that there is another way to
create a temp file but I dont remember right now.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Fabian" <fa***********@N-O-S-P-A-M.itacs.de> wrote in message
news:Og**************@TK2MSFTNGP14.phx.gbl...
Hi

I want to change the content of text file.
I use an StreamReader to read but I canīt use a StreamWriter for the same
Stream.

What I must do to implement content changing?

Thanks for help
Fabian

Nov 16 '05 #4
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,

Writting the file that you are reading is fine ONLY IF you will no change
the size of it and you only write on the part that you read already,
otherwise you could overwrite the original content.
It's much better if you create a temp file, write to it and when done just delete the original file and rename the temp file.

You can use Path.GetTempPath() to create the new file in
and Guid.NewValue() to name the file with an unique filename.

Something in the back of my head tells me that there is another way to
create a temp file but I dont remember right now.


Surely:

Create a new_file.
Read old_file.
Wite old_file to new_file.
Substitute what you want to change -- write to new_file.
Carry on writing old_file to new_file.
Blow up old_file.
Rename new_file to old_file.
Nov 16 '05 #5

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

Similar topics

28
by: Tony Carnell | last post by:
Hi all, A couple of days ago I posted a message to this newsgroup relating to the fact that a design I'd worked on for a client wasn't displaying its stylesheet in Mozilla browsers. I was...
3
by: Mike Barnard | last post by:
Hi all, newbie here. Odd sounding subject but I can't describe it any better. I'm trying to teach myself a little about CSS. In a test site (not published) I am trying to use CSS to make...
0
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the...
5
by: manokumar | last post by:
hiye, i notice that some if not all of my folders in winxp pro. are set as read only and its giving me some problem with development. so as the natural thing, i unchecked the read only option and...
2
by: Joel D Kraft | last post by:
I'm using controls in my ASP.NET application from a couple of vendors. Between the vendors and thier versioning, I've set up subfolders under my bin directory: bin bin\Infragistics\v5.2...
2
by: | last post by:
I have code to download a file from a webserver to a local machine through the browser using code dim file as System.IO.FileInfo = new System.IO.FileInfo("c:\_6_test.txt") Response.Clear();...
3
by: TomislaW | last post by:
I am sending word document with e-mail from asp.net 2.0 application. I read doc file like this:FileStream fs = System.IO.File.Open(docPath,FileMode.Open,FileAccess.Read,FileShare.Read); Then...
1
by: st12iker | last post by:
I have a datafile with the following format from which I need to extract parts of the text and copy to a seperate file : Header (line 1) --------------------------- (line 2starts) Content -...
0
by: pthawkes | last post by:
Hello I am having problems downloading a pdf file that I generate on the fly. The file download will work in IE7 and Firefox, but not in IE6 as per this post http://drupal.org/node/93787 I...
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: 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
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?
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
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,...

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.