Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Insert data in a file

Posted on 2003-02-25
3
Medium Priority
?
388 Views
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))
        fs.Flush()
        fs.Close()

The code above overwrites the data from 4th byte to 8th byte (because Int32 is 4 bytes) and writes there the new data.
 
0
Comment
Question by:gtsoulou
2 Comments
 
LVL 6

Accepted Solution

by:
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.
0
 
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

569 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