Click here to Skip to main content
15,911,139 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
i have tried to write into a file..now i am able to write but not able to write into perticular position in a file



What I have tried:

i have tried to write into a file..now i am able to write but not able to write into perticular position in a file
Posted
Updated 28-Feb-16 22:59pm
Comments
dan!sh 29-Feb-16 4:50am    
Update the question with code you have tried. Only post relevant code. Do not clutter comment section with code.

1 solution

You're looking for the Stream.Seek(..)[^]-method with which you can position your "virtual cursor" in a stream (which may be a file).

Be aware that writing "in the middle" of a stream will not insert whatever you're writing but it will overwrite whatever already is at that position. There's no simple switch to change this; if you'd want to insert, you'd have to move the remainder backwards yourself by reading and re-writing it.

Depending on which particular class you're using for file-access you might find the Seek-method not directly on that class-object but under the BaseStream-property, e.g.: myStreamWriter.BaseStream.Seek(..) .

Also be aware that the ability to seek is not generally allowed for a stream, with files you'll usually be able to though. You can check whether a stream allows seeking with its property .CanSeek .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900