I have a stream writer that opens using a WebClient.OpenWrite call. For this simplified case, assume that reader is reading a multiple of dataChunkSize.
using (Stream writer = myWebClient.OpenWrite(myURIString)
{
using (FileStream reader = new FileStream(myFileName, FileMode.Open, FileAccess.Read)
{
for(int i = 0; i < reader.Length; i += dataChunkSize)
{
byte[] data = new byte[dataChunkSize];
reader.Read(data, 0, dataChunkSize);
writer.Write(data, 0, dataChunkSize);
}
reader.Close();
reader.Dispose();
}
writer.Close();
writer.Dispose();
}
My data is the size of 2 dataChunkSizes. However, it does not send any data (no data is received) until the writer.Close() call is called, where it only sends the first dataChunkSize worth of data…the second dataChunkSize of data is never sent.
How can I get it to send after every Write call? I tried adding writer.Flush() but this did not help.
Thanks.
I think your issue is because your last chunk is perhaps not the full length you expect (dataChunkSize). Also, I would add Flush to force each write there and then if needed (thou I am not sure if the flush will work). Try changing you for loop contents to this…