Insert data in a file

Posted on 2003-02-25
Medium Priority
Last Modified: 2008-02-01
Hi. I want to insert some data in a file. The file allready exists and has data. So I want to write in this file but not at the end of file, whithout overwritting the existing data in this possition and without using a temporary file. I tried this code but doesn't works because the new data overwrites the old:

Dim fs As FileStream = New FileStream("data.bin", FileMode.OpenOrCreate, FileAccess.Write)
        Dim w As BinaryWriter = New BinaryWriter(fs)      ' create a BinaryWriter

        w.BaseStream.Seek(4, SeekOrigin.Begin) ' seek the beginning of the file after 4bytes
        w.Write(CType(CInt(TextBox1.Text), Int32))

The code above overwrites the data from 4th byte to 8th byte (because Int32 is 4 bytes) and writes there the new data.
Question by:gtsoulou
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

holli earned 400 total points
ID: 8017808
this task is not possible. you will ALWAYS have to rewrite the old data from the point you want to insert new data.
LVL 96

Expert Comment

by:Bob Learned
ID: 9649736
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by holli

Please leave any comments here within the next seven days.


EE Cleanup Volunteer

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question