MrUploader.FileUpload.WriteCallback C# (CSharp) Method

WriteCallback() private method

private WriteCallback ( IAsyncResult asynchronousResult ) : void
asynchronousResult IAsyncResult
return void
        private void WriteCallback(IAsyncResult asynchronousResult)
        {
            ErrorCode = Constants.NoError;
            try
            {
                HttpWebRequest webrequest = (HttpWebRequest)asynchronousResult.AsyncState;
                Stream requestStream = webrequest.EndGetRequestStream(asynchronousResult);

                int curChunkSize = (int)(currentChunkEndPos - currentChunkStartPos + 1);
                byte[] buffer = new Byte[curChunkSize];
                int bytesRead = 0;

                Stream fileStream = File.OpenRead();

                fileStream.Position = currentChunkStartPos;
                bytesRead = fileStream.Read(buffer, 0, curChunkSize);
                requestStream.Write(buffer, 0, bytesRead);

                requestStream.Flush();
                fileStream.Close();
                requestStream.Close();
                webrequest.BeginGetResponse(new AsyncCallback(ReadCallback), webrequest);
            }
            catch (WebException ex)
            {
                ErrorCode = Constants.HttpError;
                setErrorDescription(ex, "Ex2");
            }
            catch (IOException ex)
            {
                ErrorCode = Constants.IOError;
                setErrorDescription(ex, "Ex2");
            }
            catch (Exception ex)
            {
                ErrorCode = Constants.OtherError;
                setErrorDescription(ex, "Ex2");
            }
            if (ErrorCode != Constants.NoError)
            {
                SetFileStatus();
            }
        }