Click here to Skip to main content
15,902,918 members
Home / Discussions / C#
   

C#

 
GeneralRe: How would you write this in Linq? Pin
led mike12-Sep-08 6:44
led mike12-Sep-08 6:44 
GeneralRe: How would you write this in Linq? Pin
leppie12-Sep-08 4:58
leppie12-Sep-08 4:58 
GeneralRe: How would you write this in Linq? Pin
Pete O'Hanlon12-Sep-08 5:08
mvePete O'Hanlon12-Sep-08 5:08 
AnswerRe: How would you write this in Linq? Pin
Pete O'Hanlon12-Sep-08 5:07
mvePete O'Hanlon12-Sep-08 5:07 
QuestionStreamWriter and seek Pin
captjack12-Sep-08 4:31
captjack12-Sep-08 4:31 
AnswerRe: StreamWriter and seek Pin
Alan N12-Sep-08 5:41
Alan N12-Sep-08 5:41 
GeneralRe: StreamWriter and seek Pin
captjack12-Sep-08 6:00
captjack12-Sep-08 6:00 
AnswerRe: StreamWriter and seek Pin
Guffa12-Sep-08 7:03
Guffa12-Sep-08 7:03 
captjack wrote:
I read somewhere that the buffers might need to get flushed/reset, but can't seem to find that method.


Where did you look? Everywhere but in the StreamWriter class? Wink | ;)

You have to use the Flush method of the StreamWriter before you move the position in the underlying stream, otherwise it may write whatever is in the buffer to the new position:
using (FileStream fs = new FileStream("c:\\textFile.txt", FileMode.Open, FileAccess.ReadWrite)) {
   using(StreamWriter sw = new StreamWriter(fs)) {
      sw.BaseStream.Seek(10, SeekOrigin.Begin);
      sw.Write("0005");
      sw.Flush();
      sw.BaseStream.Seek(1, SeekOrigin.Begin);
      sw.Write("Test");
   }
}

Setting auto-flush (as suggested elsewhere in the thread) works, but if you use it when writing more than a few strings to a file you can reduce the performance, as a whole cluster (about 8 kiB) is written to the disk each time.

Also, you have to be very careful when changing the position to write in a text file. Characters outside the ASCII character set use more than a single byte in the file, so you can easily corrupt characters in the file by overwriting part of a multi-byte character. Be careful only to write single-byte characters and only overwrite single-byte characters.

Despite everything, the person most likely to be fooling you next is yourself.

QuestionNumber of query values and destination fields are not the same. Pin
Vimalsoft(Pty) Ltd12-Sep-08 4:29
professionalVimalsoft(Pty) Ltd12-Sep-08 4:29 
AnswerRe: Number of query values and destination fields are not the same. Pin
mark_w_12-Sep-08 4:35
mark_w_12-Sep-08 4:35 
GeneralA question back to you :p Pin
mark_w_12-Sep-08 4:48
mark_w_12-Sep-08 4:48 
GeneralRe: A question back to you :p Pin
The Cake of Deceit12-Sep-08 5:58
The Cake of Deceit12-Sep-08 5:58 
GeneralRe: A question back to you :p Pin
Vimalsoft(Pty) Ltd12-Sep-08 9:46
professionalVimalsoft(Pty) Ltd12-Sep-08 9:46 
GeneralRe: A question back to you :p Pin
Vimalsoft(Pty) Ltd12-Sep-08 9:49
professionalVimalsoft(Pty) Ltd12-Sep-08 9:49 
GeneralRe: Number of query values and destination fields are not the same. Pin
Vimalsoft(Pty) Ltd12-Sep-08 9:44
professionalVimalsoft(Pty) Ltd12-Sep-08 9:44 
AnswerRe: Number of query values and destination fields are not the same. Pin
Ashfield12-Sep-08 4:35
Ashfield12-Sep-08 4:35 
AnswerRe: Number of query values and destination fields are not the same. Pin
Langa Shabangu12-Sep-08 8:40
Langa Shabangu12-Sep-08 8:40 
GeneralRe: Number of query values and destination fields are not the same. Pin
Vimalsoft(Pty) Ltd12-Sep-08 9:43
professionalVimalsoft(Pty) Ltd12-Sep-08 9:43 
Questionserver is Running or not? Pin
balu1234512-Sep-08 4:11
balu1234512-Sep-08 4:11 
AnswerRe: server is Running or not? Pin
Paul Conrad12-Sep-08 5:37
professionalPaul Conrad12-Sep-08 5:37 
AnswerRe: server is Running or not? Pin
leppie12-Sep-08 5:52
leppie12-Sep-08 5:52 
QuestionReporting of operating system Pin
Matt Fishbeck12-Sep-08 4:10
Matt Fishbeck12-Sep-08 4:10 
AnswerRe: Reporting of operating system Pin
michaelvdnest12-Sep-08 4:38
michaelvdnest12-Sep-08 4:38 
AnswerRe: Reporting of operating system Pin
michaelvdnest12-Sep-08 4:39
michaelvdnest12-Sep-08 4:39 
QuestionUser PC and Server on WAN Pin
balu1234512-Sep-08 4:05
balu1234512-Sep-08 4:05 

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.