I was green when I started using this stuff 6 months ago, so I need to
revisit some of this stuff. I was "under the gun" to get stuff out at the
time. BTW, here's the solution I've used for now, and you're right, it's a
hack, but it works for now.
Thanks again for your help. I really appreciate it.
// create a web request to pass the drill link to. We'll set
// the timeout to what we have in the web.config file
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(m_drillLink);
// the web request object's Timeout property expects the number
// in milliseconds
int iTimeoutInMinutes =
Convert.ToInt32(ConfigurationSettings.AppSettings["dlTimeout"]);
wr.Timeout = (1000 * 60) * iTimeoutInMinutes;
// create a response object so we can retrieve the stream. The stream
// will let us read the response from the URL we passed.
HttpWebResponse webResponse = (HttpWebResponse)wr.GetResponse();
System.IO.Stream strm = webResponse.GetResponseStream();
// create an array list that will hold the binary bytes
// in chunks. Each chunk will then be read back and assembled
// into one byte binary array. We have to do it this way
// because the stream object doesn't know the length of the
// stream, so we have to determine it dynamically.
ArrayList arBytes = new ArrayList();
// we'll use 1024 size chunks to read the data stream.
// we'll keep track of the total number of bytes read
// and how many characters are read with each request.
int iChunk = 1024, iCharsRead = 0;
long lTotalBytesRead = 0;
// create a hold buffer we'll put the data into. We'll
// initialize using the chunk size.
Byte[] bufHold = new Byte[iChunk];
// make the initial read into the hold buffer
iCharsRead = strm.Read(bufHold, 0, iChunk);
// create a buffer using the actual # of chars read
// and copy the contents of the hold buffer into this
// one. We do this to make sure that the buffer we
// want to save into the array list always has the
// actual number of characters read.
Byte[] buf = new Byte[iCharsRead];
Array.Copy(bufHold, 0, buf, 0, iCharsRead);
// when no more chars are available to read, then the
// # of chars read will be 0, so let's loop until all
// the bytes have been read from the stream
while (iCharsRead != 0)
{
// keep track of the total bytes read to use later
// to reconstruct all the blocks into one Byte array
lTotalBytesRead += iCharsRead;
// add the current buffer block
arBytes.Add(buf);
// reinitialize the hold buffer and read the next
// block into it
bufHold = new Byte[iChunk];
iCharsRead = strm.Read(bufHold, 0, iChunk);
// reinitialize the store buffer using the actual #
// of bytes read and copy into it from the hold buffer
buf = new Byte[iCharsRead];
Array.Copy(bufHold, 0, buf, 0, iCharsRead);
}
// create the binary string we'll use to send the data
// to the user. We'll initialize it to the total # of
// bytes we've read from the stream.
Byte[] binStr = new Byte[lTotalBytesRead];
// set the index to 0 to start. This will be incremented
// as we read each block and store it starting at the
// index location pointed to by iIdx.
int iIdx = 0;
// loop through the Byte array list and process for each
// array list's Byte[] object.
foreach (Byte[] dataBuf in arBytes)
{
// copy the contents of dataBuf into binStr starting
// at the iIdx index location.
dataBuf.CopyTo(binStr, iIdx);
// increment the index location by the content Byte[]'s
// length to make sure the next block is written at the
// correct starting location.
iIdx += dataBuf.Length;
}
// Release the response object resources.
strm.Close();
webResponse.Close();