Click here to Skip to main content
15,889,609 members
Home / Discussions / C#
   

C#

 
GeneralRe: Why doesn´t work the Code? Pin
nhqlbaislwfiikqraqnm20-Aug-09 0:02
nhqlbaislwfiikqraqnm20-Aug-09 0:02 
GeneralRe: Why doesn´t work the Code? Pin
Luc Pattyn20-Aug-09 0:37
sitebuilderLuc Pattyn20-Aug-09 0:37 
GeneralRe: Why doesn´t work the Code? Pin
Keith Barrow20-Aug-09 0:39
professionalKeith Barrow20-Aug-09 0:39 
GeneralRe: Why doesn´t work the Code? Pin
Pete O'Hanlon20-Aug-09 1:02
mvePete O'Hanlon20-Aug-09 1:02 
GeneralRe: Why doesn´t work the Code? [modified] Pin
nhqlbaislwfiikqraqnm20-Aug-09 9:04
nhqlbaislwfiikqraqnm20-Aug-09 9:04 
Questionwrite at a particular position in a text document Pin
firefeet19-Aug-09 22:36
firefeet19-Aug-09 22:36 
AnswerRe: write at a particular position in a text document Pin
musefan19-Aug-09 23:13
musefan19-Aug-09 23:13 
AnswerRe: write at a particular position in a text document Pin
Keith Barrow19-Aug-09 23:24
professionalKeith Barrow19-Aug-09 23:24 
Here is one method:

1. Open a StreamReader
2. Open a StreamWriter to the new file
3. Do a ReadLine on the StreamReader y times, writing the result to the StreamWriter using WriteLine
4. On the Stream Reader Do a ReadBlock(x) and call Write on the StreamWriter, passing in the result.
5. Write the text to be inserted
6. Call StreamReader.ReadToEnd() and write the results to file using the Writer.

There are a couple of things to look out for:
a) The algorith I have given you writes to the correct position. There could be out-by-one errors (e.g. writing to a character or line before of after the one desired) as I haven't tested it.
b) You'll get exceptions if y is greater than the length of the file. Similarly, if x is greater than the length of line y, an exception will be thrown

Take a look at http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx[^], the "HowTos" at the bottom contain "How to Read from File" and "How to Write to File" links which will be useful.
GeneralRe: write at a particular position in a text document Pin
firefeet20-Aug-09 0:00
firefeet20-Aug-09 0:00 
GeneralRe: write at a particular position in a text document Pin
Keith Barrow20-Aug-09 0:22
professionalKeith Barrow20-Aug-09 0:22 
GeneralRe: write at a particular position in a text document Pin
firefeet20-Aug-09 0:30
firefeet20-Aug-09 0:30 
GeneralRe: write at a particular position in a text document Pin
Luc Pattyn20-Aug-09 0:41
sitebuilderLuc Pattyn20-Aug-09 0:41 
GeneralRe: write at a particular position in a text document Pin
firefeet20-Aug-09 0:51
firefeet20-Aug-09 0:51 
AnswerRe: write at a particular position in a text document Pin
Keith Barrow20-Aug-09 0:57
professionalKeith Barrow20-Aug-09 0:57 
GeneralRe: write at a particular position in a text document [modified] Pin
firefeet20-Aug-09 1:03
firefeet20-Aug-09 1:03 
AnswerRe: write at a particular position in a text document [modified] Pin
Tr@v20-Aug-09 10:20
Tr@v20-Aug-09 10:20 
GeneralRe: write at a particular position in a text document Pin
firefeet20-Aug-09 17:53
firefeet20-Aug-09 17:53 
AnswerRe: write at a particular position in a text document Pin
Tr@v21-Aug-09 7:44
Tr@v21-Aug-09 7:44 
QuestionUpdate datagrid cell Pin
bonzaiholding19-Aug-09 22:35
bonzaiholding19-Aug-09 22:35 
AnswerRe: Update datagrid cell Pin
padmanabhan N19-Aug-09 22:54
padmanabhan N19-Aug-09 22:54 
GeneralUsing Dynamic predicates (Linq) Pin
Sayed Sajid19-Aug-09 22:32
Sayed Sajid19-Aug-09 22:32 
QuestionDelegate.CreateDelegate in so non static function Pin
bonzaiholding19-Aug-09 21:56
bonzaiholding19-Aug-09 21:56 
AnswerRe: Delegate.CreateDelegate in so non static function Pin
bonzaiholding19-Aug-09 22:32
bonzaiholding19-Aug-09 22:32 
QuestionDetecting a change in excel spreadsheet cell Pin
NarVish19-Aug-09 21:29
NarVish19-Aug-09 21:29 
AnswerRe: Detecting a change in excel spreadsheet cell Pin
Rajesh R Subramanian19-Aug-09 21:33
professionalRajesh R Subramanian19-Aug-09 21:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.